# untested example code that could cause all of your .pl files to be deleted! my @fix; find {no_chdir=>1, wanted=>sub{ -f && m/\.pl$/ && push @fix,[File::Spec->splitpath($_)];} },@paths; foreach my $fix (@fix) { find { no_chdir=>1, wanted=>sub{ -f && (File::Spec->splitpath($_))[2] eq $fix->[2] && unlink $_ } },do{ (my $x=$fix->[0].$fix->[1]) =~s/foo/bar/g; $x}; }