my %totals; while ( ) { chomp; if ( /(^[a-z].*$)/i ) { $totals{$1} = 0 unless $totals{$1}; } else { $totals{$1} += $_; } } print "$_: $totals{$_}\n" for keys %totals; __DATA__ player1 11 22 11 player2 10 21 player1 22