use File::Find; use File::stat; find(\&checkFile, $path); # loop through all files in my directory #--------------------------------- check to be applied on each file ------------- sub checkFile { my $fullfilename = $File::Find::name; my $filesize = stat($File::Find::name)->size; my $filename = $_; # --- check for relevance based on expected filenames if ((! ($filename =~ /_obj_pp_comp.txt/ )) && (! ($filename =~ /obj.doc/ ))) { return; } if ($filesize == 0) { print ("\n"); return; } if (! -f $filename) { print ("\n"); return; } analyze($fullfilename); } #--------------------------------- work to be done on each relevant file ------------- sub analyze { ... }