use strict; use warnings; my $fileName = 'data.txt'; # Create the sample data file open my $outFile, '>', $fileName or die "Failed to create $fileName: $!"; print $outFile <) { chomp; my ($id, $count) = split /\s+/; next if ! $count; $counts{$id} += $count; } # Print the result for my $id (sort keys %counts) { printf "%-12s: %5d\n", $id, $counts{$id}; } #### Db04g787390.1: 28 Db10g029860.2: 34 Db96g938791.0: 25