my ($failedTest) = grep { /FAIL/ } @reportContents; ... #### for my $failedTest (grep { /FAIL/ } @reportContents) { ... }