my %totals; while ( ) { chomp; if ( /(^[a-z].*$)/i ) { #I deleted the initialization here, and you still get what you expected } else { $totals{$1} += $_; } } print "$_: $totals{$_}\n" for keys %totals; __DATA__ player1 11 22 11 player2 10 21 player1 22