# at the top of your program use constant { Key => 0, Sum => 1, Count => 2 }; # How you fill the %seen hash $seen{$key1}[Key] //= $key; ### Edit, turned = $key into //= $key $seen{$key1}[Sum] += $value; # Cumulated value of $key1 $seen{$key1}[Count] ++; # Number of time $key1 has been seen