my @files; find sub { push @files, $File::Find::name if -f and /\.txt$/ }, '.'; # now you have an array of file names: foreach(@files) { ... }