use strict; use warnings; use File::Slurp; my $path="/tmp/test"; my @files = grep { -f and /^\d{8}\.\d{6}\.host\d\.\d{1,6}$/ } read_dir $path; print "Got ". scalar(@files) . "\n";