use strict; use warnings; use Data::Dumper; my @class = (40, 40, 40, 183, 183, 259, 244, 503); my @qty = (260, 234, 211, 301, 401, 321, 210, 451); my %bin = ( 0 => [0,0], 40 => [0, 0], 183 => [0, 0], 503 => [0, 0], 442 => [0, 0], 259 => [0, 0], 244 => [0, 0]); my ($i, $hkey); for($i = 0; $i <= $#class; $i++) { $hkey = $class[$i]; my $tmp_count = $bin{$hkey}[0]+1; my $tmp_sum = $bin{$hkey}[1]+ $qty[$i]; $bin{$hkey}[0] = $tmp_count; $bin{$hkey}[1] = $tmp_sum; # $bin{$hkey}[0, 1] = [$tmp_count, $tmp_sum]; #why not? } print Dumper (%bin); #### # 0 => [ 0, 0]; # 40 => [ 3, 705]; # 183 => [ 2, 702]; # 259 => [ 1, 401]; # 442 => [ 0, 0]; # 244 => [ 1, 321]; # 503 => [ 1, 210];