my %seen; open(B, "brd_sym_pn.txt") or die "..."; while () { my ($RefDes, $Pnumm, $Pkg_Type) = ...parse these from the line... $seen{$RefDes, $Pnumm, $Pkg_Type} = 1; } close(B); open(S, "sym_text_latest.txt") or die "..."; while () { my ($RefDes, $Pnumm, $Pkg_Type) = ...parse these from the line... $seen{$Refdes, $Pnumm, $Pkg_Type} += 2; } close(S); while (my ($key, $val) = each %seen) { if ($val == 1) { # $key is in first file but not second } elsif ($val == 2) { # $key is in second file but not first } else { # key is in both files } }