while () { my ($source, $sport, $to, $dport, $proto, $packs, $bytes) = split; my $key = "$source$dport"; if ( exists( $total{$key}{from} )) { $total{$key}{connects}++; $total{$key}{bytes} += $bytes; } else { $total{$key} = { from => $source, to => "$to:$dport", bytes => $bytes, }; # maybe should set 'connects => 1' as well? } $total += $bytes; } #### perl -e '$k="aaaaa"; for $i (1..1_000_000) { $h1{$k}={foo=>"bar",bar=>"foo",iter=>$i}; $h1{$k}{total}++; $k++} sleep 20' ## consumes 344 MB in ~14.4 sec perl -e '$k="aaaaa"; for $i (1..1_000_000) {$h1{$k}={foo=>"bar",bar=>"foo",iter=>$i}; $h2{$k}++; $k++} sleep 20' ## consumes 352 MB in ~15.0 sec perl -e '$k="aaaaa"; for $i (1..1_000_000) {$h1{$k}={foo=>"bar",bar=>"foo"}; $h2{$k}++; $h3{$k}=$i; $k++} sleep 20' ## consumes 360 MB in ~16.5 sec