foreach $reg (@regex) { my $i = 0; while ($i <= $#array) { if ($array[$i] =~ /$x/) { # successful, so keep $array[$i] in array and move to the next $i++; } else { # this item didn't pass so we remove it for good and # never have to test it again. splice(@array, $i, 1); } } }