#!/usr/bin/perl while (<>) { if (/^\d+: SPAM: (hdr_\S+): (.*)$/) { $pop{$2}++; $desc{$2} = $3; } if (/^\d+: SPAM:\s+(-> .*)$/) { $pop{$1}++; $desc{$1} = $1; } } foreach $_ (sort { $pop{$b} <=> $pop{$a} } keys %pop) { printf ("%5d %s %s\n", $pop{$_}, $_, $desc{$_}); }