# pseudocode my %report; foreach my $line( $fh_one ){ if... matching.. extract the part interesting $report{ $interesting_part }[0] = 1; # first file populates the element 0 foreach my $line( $fh_two ){ if... matching.. extract the part interesting $report{ $interesting_part }[1] = 1; # first file populates the element 1 # result like %report = ( interesting1 = [ undef, 1 ], # is present only in the second file interesting2 = [ 1, undef ], # is present only in the first file interesting3 = [ 1, 1 ], # is present in both files );