in reply to Re^2: Counting instances of words
in thread Counting instances of words

Thanks for your help. Tried this, and $code appears to be empty. I've declared it outside the While loop, but it prints out as null. Should this contain the total substitutions?

Well, for one thing I wouldn't regard $code as a particularly good variable name. Then, if you want the total number of substitutions, you must accumulate them:

$count += s/\band\b/$word/ig;