use Data::Dumper; open FH,"DATA.txt" or die $!; my %hash; my ($a,$b); while() { ($a,$b)=split(' '); $hash{$a}+=$b; } print Dumper \%hash;