in reply to Word Count and Match

One more thing, I noticed you're using the /o modifier here:

if($word=~/($wordcnt)/io){
You should remove it - see regex "o" modifier especially tye's response and Aristotle's response: Never use /o

Updated: Added Aristotle's response