#!/usr/bin/perl $| = 1; # autoflush # %lines is asociative array (hash) my %lines; while () { chop; if (exists $lines{"$_"}) { $lines{"$_"} = $lines{"$_"} + 1; } else { $lines{"$_"} = 1; } } # print count for each entry in hash foreach $key (keys %lines) { print $key, " ", $lines{"$key"}, "\n"; }