in reply to opendir or not?

You mentioned twice that there's a benchmark discrepancy between the while loop and the readdir loop. While you're in a benchmarking mood, if you're so inclined, please show us the results of the three forms:
while ($eachfile = <*.txt>) { ... }
@files = <*.txt>; foreach (@files) { ... }
opendir(DIR, ...); while (defined ($eachfile = readdir(DIR) )) { next if not /\.txt$/; ... }

Of course, there's platform differences to consider, too. Some filesystems bog down worse than others with long directories.

If you're bored, check that @files = <*.txt> is really just as fast as @files = glob("*.txt"), too.

--
[ e d @ h a l l e y . c c ]