use File::Copy; use strict; my($sourcedir) = shift || die "No source dir"; opendir(DIR,"$sourcedir"); foreach (grep !/^\.\.?$/,readdir DIR) { if (/^(\S+)_(\S+)\.(\S+)$/) { if (move($_,"$1-$2.$3")) { print "Moved $_ to $1-$2.$3\n"; } else { print "Error moving $_ to $1-$2.$3\n"; } } }