We can use finddepth() in File::Find to recursively find files in a directory and do actions like renaming etc.

 

Here is a sample snippet:

{code}
use File::Find;

finddepth (\&depth, "D:\\");

sub depth {
      my $old = $_;
      my $oldName = "newsample";
      my $newName = "sample";
      s/$oldName/$newName/ or return; # don't do anything if you don't have oldname
      -e and return; # don't rename over an existing file!
      rename $old, $_ or die "cannot rename $old to $_: $!";
    }

{/code}