my @files = grep { my $f = "$dir/$_"; -f $f && $f =~ m/\.dat$/ } readdir($dh);