use strict; use warnings; my %hBase = ( 'a;a' => 1, 'b;b' => 2, 'c;c' => 3 ); my %hPost = ( 'a;a' => 1, 'b;b' => 3, 'd;d' => 4 ); my %allKeys = map {$_=>1} keys %hBase, keys %hPost; for my $key (keys %allKeys) { if( exists $hBase{$key} and exists $hPost{$key} ) { if( $hBase{$key} eq $hPost{$key} ) { print "$key in both hashes with same value $hBase{$key}\n"; } else { print "$key in both hashes with different values $hBase{$key} != $hPost{$key}\n"; } } else { print "$key in %hBase with value $hBase{$key}\n" if exists $hBase{$key}; print "$key in %hPost with value $hPost{$key}\n" if exists $hPost{$key}; } }