in reply to quick way to read a few directory entries of many

That snippet uses readdir in list context. You'd want
my $dn = '.'; my @f; opendir(my $dh, $dn) or die; while ( @f < 5 && defined( my $filename = readdir($dh) ) ){ next if $filename=~/^\.\.?\z/; push @f, $filename; }

Other changes:

Note that you'll quite likely get the same files in the same order every time. But that's how it's going to be unless you read the whole dir.