my %seen; while (<$FILE>) { chomp; ++$seen{$_}; } for my $string (keys %seen) { print "$string encountered $seen{$string} time(s).\n"; }