title: Is there a way to overload the regex binding operator `=~` in Perl?
body: <p>I am working on a small DSL that uses the <code>nomethod</code> fallback for overloading to capture the operators used on the overloaded values.  This is similar to the function of the <a href="http://perldoc.perl.org/overload.html#Symbolic-calculator" rel="noreferrer">symbolic calculator</a> described in <code>overload</code>'s documentation.</p>
  
  <p>This works fine for the standard comparison operators, but consider the following:</p>
  
  <pre><code>my $ret = $overloaded =~ /regex/;
  </code></pre>
  
  <p>In this case, <code>nomethod</code> gets called to stringify <code>$overloaded</code>, and after that the overloading is lost.  I thought about returning a tied variable, which will at least let me carry around the original overloaded object, but that will still get lost during the execution of the regex.</p>
  
  <p>So, the ultimate question is if there is any way to extend <code>overload</code>'s idea of a symbolic calculator to include the regex binding operators <code>=~</code> and <code>!~</code>, so that the above code sample would call <code>nomethod</code> with <code>($overloaded, qr/regex/, 0, '=~')</code> or something similar?</p>
  
  <p>I also briefly looked into overloading the smartmatch operator <code>~~</code> but that didn't seem to do the trick either (always defaults to regex matching rather than overloading).</p>
  
  <p>Edit: I looked into <code>~~</code> more, and found that <code>my $ret = $overloaded ~~ q/regex/</code> works due to smartmatching rules.  Close, but not an ideal solution, and I would like it to work pre 5.10, so I welcome other answers.</p>