title: Passing a regex substitution as a variable in Perl
body: <p>I need to pass a regex substitution as a variable:</p>
  <pre><code>sub proc {
      my $pattern = shift;
      my $txt = &quot;foo baz&quot;;
  
      $txt =~ $pattern;
  }
  
  my $pattern = 's/foo/bar/';
  proc($pattern);
  </code></pre>
  <p>This, of course, doesn't work. I tried eval'ing the substitution:</p>
  <pre><code>eval(&quot;$txt =~ $pattern;&quot;);
  </code></pre>
  <p>but that didn't work either. What horribly obvious thing am I missing here?</p>