my $logfile = '/tmp/senders.txt'; open my $fh, '<', $logfile or die "Could not open $logfile : $!"; my %count=(); while (my $line = <$fh>) { foreach my $word (split /\s+/, $line) { ++$count{$word}; #print "$word\n"; #print "$count{$word}\n"; #print "
"; #print " \n"; } } for my $word ( (sort { $count{$b} <=> $count{$a} } keys %count) [0..19] ) { #print "$word $count{$word}\n"; # THIS shows top 20 emails address and its count. } close $fh;