http://www.perlmonks.org?node_id=993504


in reply to hash to count words

Please use "code" tags correctly, as described in Writeup Formatting Tips.

Your regex "$word =~ s/^\w\x\//g;" is invalid.

you probably want:

$word=~s/[^\w]//g; # Eliminate non-word chars
Your re-initilazation of "%hash=()" within the loop makes the hash useless.

Declare it outside the loop, and add data to it using

$hash{$word}++; # Get a count of the word
Later , you can get a list of words found by accessing:
keys (%hash)
Please try to follow davido's excellent advice in response to your previous question on the same subject.

             I hope life isn't a big joke, because I don't get it.
                   -SNL