title: Use variable as RegEx pattern
body: <p>I'd like to use a variable as a RegEx pattern for matching filenames:</p>
  
  <pre><code>my $file = "test~";
  my $regex1 = '^.+\Q~\E$';
  my $regex2 = '^.+\\Q~\\E$';
  print int($file =~ m/$regex1/)."\n";
  print int($file =~ m/$regex2/)."\n";
  print int($file =~ m/^.+\Q~\E$/)."\n";
  </code></pre>
  
  <p>The result (or on <a href="http://ideone.com/x2TbFm">ideone.com</a>):</p>
  
  <pre><code>0
  0
  1
  </code></pre>
  
  <p>Can anyone explain to me how I can use a variable as a RegEx pattern?</p>