my @matches; foreach $reg (@regex) { my $i = 0; while ($i <= $#array) { if ($array[$i] =~ /$x/) { # successful, so this was a match! put it somewhere safe # also remove it from @array, we don't need to check it again push @matches, $array[$i]; splice(@array, $i, 1); } else { # this item didn't pass so keep it and try again next regex $i++; } } }