use strict; use warnings; my %data; open (DATA1, "<", "data1.txt") or die "cannot open file"; while () { my @line = split (/\t/, $_); $data{$line[0]} = $line[1]; } my @k = keys %data; foreach my $key (@k) { print "$key, $data{$key}\n"; } close DATA1; open (DATA2, "<", "data2.txt") or die "cannot open file"; print "found:\n"; while () { chomp; if (exists $data{"$_"}) {print "$data{$_}\n";} close DATA2;