foreach (@list1){ @temp=split(/\s+/, $_); } #### # create lookup table while () { chomp; $CVDgenes{$_} = 1; } # go through the other file and check if its entries # are found in the lookup table: while (){ chomp; my ($gene, $gid) = split(/\s+/, $_); if (exists $CVDgenes{$gene}) { print "The GID for gene $gene is $gid\n"; } }