open(FH,"file"); foreach $line () { if($line=~/^Db/) ### Get only the ID lines. { ($id,$count)=split(' ',$line); $count{$id}+=$count; } } print "ID\t\tCount\n"; foreach $key (keys%count) { print "$key\t$count{$key}\n" }