use strict; use warnings; use Cwd; use File::Find; # Return a list of the absolute path of all plain .txt files under $dir sub FindTextFiles { my $dir = shift; my @files; # Note: -f = plain file (perldoc -f -X for doco of all file tests) find( { no_chdir => 1, wanted => sub { -f && /\.txt$/ and push @files, $File::Find::name } }, $dir ); return @files; } my $dir = getcwd(); my @txtfiles = FindTextFiles($dir); print "Found ", scalar(@txtfiles), " text files under dir '$dir'...\n"; for my $file (@txtfiles) { print "file='$file'\n"; # could add code to modify the found files here ... }