title: Using Perl to rename files in a directory
body: <p>I'd like to take a directory and for all email (*.msg) files, remove the 'RE ' at the beginning. I have the following code but the rename fails.</p>
  
  <pre><code>opendir(DIR, 'emails') or die "Cannot open directory";
  @files = readdir(DIR);
  closedir(DIR);
  
  for (@files){
      next if $_ !~ m/^RE .+msg$/;
      $old = $_;
      s/RE //;
      rename($old, $_) or print "Error renaming: $old\n";
  }
  </code></pre>