maybe you can loop your words and find if(x == 'd' && x+1 == 'o' && x+2 == 'g') then there's a dog word inside your text.
Let's keep everything in C2 event system scope/context shall we?
Use codah's suggestion to just check whether "dog" exist.
Use [tokencount("yourText","dog")-1] to check how many occurence "dog" has.
Use event below if you want to check all index (zero-based) of occurence.
Condition: Repeat tokencount("yourText"," ")
Condition: compare tokenat("yourText",loopindex," ") = "dog"
Action: add <textVariable> with "_"&loopindex[/code:1sejahw6]
Example, if "yourText" is "the dog the dog the dog the dog the dog"
you should get <textVariable> = _1_3_5_7_9