in reply to I need a perl script to make every instance of a repeated word unique

The substitution that you will need is s/\bundefined\b/"undefined" . ++$count/eg.

perlop has instructions for how to use such substitutions (look for "s/PATTERN/REPLACEMENT"), and perlrun documents the -p and -e flags which are likely to prove very useful for you.