use warnings; use File::Find; use 5.010; use POSIX; find(\&dirRecurs, '/users/my-dir/tree-to-work-on'); sub dirRecurs{ if ((my $txt = $_) =~ s/^\ | (?=\.)|[\/!#%^:<>?*&()\\]| $//g && -f != m/^\./) { my $filename = '/users/my-dir/fix_names_report.txt'; open(my $fh, '>>', $filename); if (! -e $txt){ rename($_, $txt); say $fh (strftime "%Y-%m-%d %H:%M:%S", localtime time)," \: ", $_, " => ", $txt; } else { say $fh ("!!! ", strftime "%Y-%m-%d %H:%M:%S", localtime time)," \: ", $_, " => NOT RENAMED =>", $txt, " already exists."; } close $fh; } }