use strict; use warnings; use Data::Dumper; sub are_hashes_equal { my ($hash1,$hash2)=@_; return 1 if $hash1==$hash2; my %temp=%$hash2; foreach my $key (keys %$hash1) { return 0 unless exists $temp{$key} and defined($hash1->{$key}) eq defined($temp{$key}) and (defined $temp{$key} ? $temp{$key} eq $hash1->{$key} : 1); delete $temp{$key}; } return !keys(%temp); } my %aa=(uno=>1, due=>2,trio=>undef,quat=>0,cinq=>''); my @b=( \%aa, {uno=>1, due=>2,trio=>undef,quat=>0,cinq=>''}, {uno=>1, due=>2,trio=>0,quat=>undef,cinq=>''}, {uno=>2, due=>2,trio=>undef,quat=>0,cinq=>''}, {uno=>2, due=>2,trio=>undef,quat=>0}, {uno=>2, due=>2,trio=>undef,quat=>0,cinq=>'',sex=>'is fun'}, ); print Data::Dumper->Dump([\%aa],['*aa']); foreach my $test_id (0..$#b) { print Data::Dumper->Dump([$b[$test_id]],['*test'.$test_id]); print "Is ",(are_hashes_equal(\%aa,$b[$test_id]) ? '' : 'not '), "the same as %aa\n\n"; }