while (my $line = <$fh>) { chomp $line; my @words = split /\W+/, $line; for my $word (@words) { ++$count{$word} if exists $count{$word}; } }