title: uniquely rename each of many files using perl
body: <p>I have a folder containing 96 files that I want to rename. The problem is that each file name needs a unique change...not like adding a zero the front of each name or changing extensions.  It isn't practical to do a search and replace.
  Here's a sample of the names I want to change:</p>
  
  <pre><code>newSEACODI-sww2320H-sww24_07A_CP.9_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07B_CP.10_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07C_CP.11_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07D_CP.12_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07E_R.1_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07F_R.3_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07G_R.4_sww2320H_sww2403F.fsa
  newSEACODI-sww2320H-sww24_07H_R.5_sww2320H_sww2403F.fsa
  </code></pre>
  
  <p>I'd like to use perl to change the above names to the below names, respectively:</p>
  
  <pre><code>SEACODI_07A_A.2_sww2320H_2403F.fsa
  SEACODI_07B_A.4_sww2320H_2403F.fsa
  SEACODI_07C_H.1_sww2320H_2403F.fsa
  SEACODI_07D_H.3_sww2320H_2403F.fsa
  SEACODI_07E_H.6_sww2320H_2403F.fsa
  SEACODI_07F_H.7_sww2320H_2403F.fsa
  SEACODI_07G_Rb.4_sww2320H_2403F.fsa
  SEACODI_07H_Rb.9_sww2320H_2403F.fsa
  </code></pre>
  
  <p>Can such a thing be done?  I have a vague idea that I might make a text file with a list of the new names and call that list @newnames.  I would make another array out of the current file names, and call it @oldnames.  I'd then do some kind of <code>for</code> loop where each element $i in @oldnames is replaced by the corresponding $i in @newnames.</p>
  
  <p>I don't know how to make an array out of my current file names, though, and so I'm not sure if this vague idea is on the right track.  I keep my files with the messed-up names in a directory called 'oldnames'. The below is my attempt to make an array out of the file names in that directory:</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict; use warnings;
  
  my $dir = 'oldnames';
  opendir ('oldnames', $dir) or die "cannot open dir $dir: $!";
  my @file = readdir 'oldnames';
  closedir 'oldnames';
  
  print "@file\n";
  </code></pre>
  
  <p>The above didn't seem to do anything. I'm lost. Help?</p>