use strict; use warnings; my %result; open my $A, "<", "file1" or die "could not open file1 $!"; while (<$A>) { chomp; my $key = (split /\t/, $_)[0]; $result{$key} = 1; } close $A; open my $B, "<", "file2" or die "could not open file2 $!"; while (<$B>) { chomp; my $key = (split /\t/, $_)[0]; $result{$key}++; } close $B; open my $C, "<", "file3" or die "could not open file3 $!"; while (<$C>) { chomp; my $key = (split /\t/, $_)[0]; if ($result{$key} == 2) { # this key has been seen in both previous files print "Line with $key is present in all three files\n"; } } close $C;