for (my $i=0; $i < 5; $i++){ opendir(DIR,$i) or die(); foreach my $file (readdir(DIR)) { # if the filename ends in "test.txt"... # adjust the regex as needed if ($file =~ /test\.txt$/) { print "$i, -${file}-\n"; } } closedir(DIR); } #### use Benchmark; timethese(10000, { 'readdir' => sub { my @blah; for (my $i=0; $i < 5; $i++){ opendir(DIR,$i) or die(); foreach my $file (readdir(DIR)) { if ($file =~ /test.txt$/) { push(@blah,$file); } } closedir(DIR); } }, 'glob' => sub { my @blah; for (my $i=0; $i < 5; $i++){ for (<$i/*test.txt>) { push(@blah,$_); } } } } ); Results on my perl 5.6.x box: Benchmark: timing 10000 iterations of glob, readdir... glob: 12 wallclock secs ( 3.24 usr + 2.22 sys = 5.46 CPU) @ 1831.50/s (n=10000) readdir: 3 wallclock secs ( 1.54 usr + 1.69 sys = 3.23 CPU) @ 3095.98/s (n=10000) on a 5.005_003 box (1000 iterations, because it's so slow): Benchmark: timing 1000 iterations of glob, readdir... glob: 216 wallclock secs ( 1.83 usr 9.21 sys + 63.22 cusr 107.38 csys = 0.00 CPU) readdir: 1 wallclock secs ( 0.43 usr + 0.37 sys = 0.80 CPU)