for (my $i=0; $i<@genes; $i++) { foreach my $id (@uniq) { if ($genes[$i] =~ /^\Q$id/) { print "$id\n"; } } }