sub rename($) { my $path = $_[0]; #append a trailing / if it's not there if($path !~ /\/$/) { $path .= '/'; } #loop through the files contained in the directory for my $eachFile (glob($path.'*')) { #if the file is a directory if(-d $eachFile) { #pass the directory to the routine ( recursion ) rename($eachFile); } else { my @strings = split('/', $eachFile); my $fileName = $strings[$#strings]; my $filePath = '/'.join('/', @strings[2..$#strings-1]); system("mv $filePath/$fileName $filePath/\"YourNewNameHere\""); } } }#rename