Note: I added a third parameter of 1 to each use of $pos() since it seems from the context that you want it to return the first position of the word in %msg, not the number of times it appears.
Hm... I've used $pos without the 1 and I get the position of the first word. I don't get the number of times it appears. (v6.2)