foreach my $orth (@orthologs) { my $hit; if ($orth =~ /^A(\d+)/) { $hit=$1; } for (my $i=0; $i<@pids; $i++) { if ($pids[$i] =~ /$hit/) { push @hits, $hit; } else { push @potential_hgt, $pids[$i]; } } }