while (($value,$key) = each %hFields) { if (defined($rHash->{$key})) { $rHash->{$key}->{'count'}+= $value; } else { $rHash->{$key}->{'count'} = $value; } $total+= $value; } } print "Total = $total\n", Dumper ($rHash);