use File::Find; .... .... find (\&wanted, "$target_path"); sub wanted { open temp_file_cy, "$File::Find::name; print "hello 1\n" if (-r tep_file_cy); close temp_file_cy; }