# Assuming %words is the hash where you keep all the words $words{$_}++ for split /\s+/, $line;