use strict; use warnings; my ($dir, $file) = './'; ### Directory to process opendir(DIR, $dir) || die; while ($file = readdir(DIR)) { if ($file !~ /_my_guitar\.mp3/ && $file =~ /(.*)\.mp3/) { $_ = "$1_my_guitar.mp3"; `mv $dir$file $dir$_`; ### Or some other rename } }