for (<>) { chomp; /(\d+)\s+(\d+)/ or next; $total{$1} += $2; } for (sort { <=> } keys %total) { print "$_ = $total{$_}\n"; }