PARENT: foreach $one (@one) { foreach $two (@two) { $one =~ m/\(.\)(.+)\(.\)/; if ($two eq $1) { push @result, $one; next PARENT; } } }