in reply to Shorten a list...
Keep a count of occurrences of each group in a hash.
Improve your skills with Modern Perl: the free book.