#!/usr/bin/env perl use strict; use warnings; my %freqs = (); # .... # for each match of $word $freqs{$word}++; # ... # the list the counts: foreach my $word (keys(%freqs)) { print "$word: $freqs{$word}\n"; } 1;