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 ... } #### Found 5 text files under dir 'C:/pm/file-find'... file='C:/pm/file-find/example.txt' file='C:/pm/file-find/fred/f1/zz.txt' file='C:/pm/file-find/fred/f2/hello.txt' file='C:/pm/file-find/fred/f2/f2a/2a.txt' file='C:/pm/file-find/fred/f2/f2a/hello.txt'