title: How to pass a replacing regex as a command line argument to a perl script
body: <p>I am trying to write a simple perl script to apply a given regex to a filename among other things, and I am having trouble passing a regex into the script as an argument. </p>
  
  <p>What I would like to be able to do is somthing like this:</p>
  
  <pre><code>&gt; myscript 's/hi/bye/i' hi.h
  bye.h
  &gt;
  </code></pre>
  
  <p>I have produced this code</p>
  
  <pre><code>#!/utils/bin/perl -w
  use strict;
  use warnings;
  
  my $n_args = $#ARGV + 1;
  my $regex =  $ARGV[0];
  for(my $i=1; $i&lt;$n_args; $i++) {
    my $file = $ARGV[$i];
  
    $file =~ $regex;
    print "OUTPUT: $file\n";
  }
  </code></pre>
  
  <p>I cannot use qr because apparently it cannot be used on replacing regexes (although my source for this is a forum post so I'm happy to be proved wrong).</p>
  
  <p>I would rather avoid passing the two parts in as seperate strings and manually doing the regex in the perl script.</p>
  
  <p>Is it possible to pass the regex as an argument like this, and if so what is the best way to do it?</p>