opendir DIR, $directory or die $!; while (my $entry = readdir DIR) { ... next if $entry !~ m/^$prefix/; # Prefix doesn't match => next filename next if $entry !~ m/$suffix$/; # Sufffix doesn't match => next filename ... }