my @file = grep {/BLAH/} readdir (DIR); foreach $file @file { do something; }