my %classification; # Scan and "bucket" the items for each $thing (@source_of_things) { # If the thing needs to be transformed, truncated, or pattern-matched, # do that here to get the unique part you're interested in. $classification{$unique_part_of_thing}++; } # Analyze and report. foreach $item (keys %classification) { print "$item found $classification{$item} time", ($classification{$item}==1 ? '' : "s"), "\n"; # Or whatever you need to do with each unique item and the number of # times it was found. }