#!/usr/bin/perl -wT while (<>) { if ($_ =~ /You are (.*), (worshipping|and not)/) { $counts{$1}++; } } foreach $key (keys %counts) { print $counts{$key} . "\t" . $key . "\n"; }