use strict; use warnings; use File::Find; my $dir = shift; find(\&change_ext_if_file, $dir); sub change_ext_if_file { my $file= $File::Find::fullname; return if -d $file; # skip directories return if $file !~ /\.pdf/i; # Ignore anything that's not a .pdf (my $newName = $file) =~ s/pdf$/doc/i; #do whatever needs to be done with the new filename - rename maybe? #rename $file, $newName; }