use strict; my %hash; open( F, "<", "file1" ) or die "file1: $!"; while () { my ( $name, $val ) = split; $hash{$name} = $val; } open( F, "<", "file2" ) or die "file2: $!"; while () { my ( $name, $val ) = split; if ( exists( $hash{$name} ) { my $status = ( $hash{$name} eq $val ) ? 'OK':'WRONG'; print "$name\t$status\t$hash{$name}\n"; delete $hash{$name}; # don't need this anymore } } # any keys left in hash are cases where a file1 name was not found in file2 # so print those now: if ( keys %hash ) { print "\nNames not found in file2:\n"; print "$_\t$hash{$_}\n" for ( sort keys %hash ); }