foreach $file (@array) { if ($file =~ /^KL\d+_/) { push (@files, $file); print "$file\n"; } }