my %h1 = map { ( $_ => 1 ) } qw( a b c d e f g h ); my %h2 = map { ( $_ => 1 ) } qw( b c d e f g h i ); my %h3 = map { ( $_ => 1 ) } qw( c d e f g h i j ); my %h4 = map { ( $_ => 1 ) } qw( d e f g h i j k ); my %summed = add_hashes( \%h1, \%h2, \%h3, \%h4, ); use Data::Dumper; $Data::Dumper::Sortkeys=1; print Dumper \%summed;