my $var = [ { "D1" => 1, "D2" => 2 }, { "D2" => 5, "D3" => 6 }, ]; my %combined; foreach my $subhash (@$var) { foreach my $key (keys %$subhash) { $combined{$key} += $subhash->{$key}; } } my @sorted_keys = sort { $combined{$b} <=> $combined{$a} } keys %combined; foreach my $key (@sorted_keys) { print("$key: $combined{$key}\n"); }