while(){ @tmp = split; $key = shift @tmp; $cache{$key}[0] += $tmp[0]; $cache{$key}[1] += $tmp[1]; } close IN; foreach (keys %cache){ print OUT $_," ",join( " ", @{$cache{$_}}), "\n"; } close OUT;