in reply to Perl substitute with the nth match

Use /e to execute code to generate the substitution.

s{ cat }{ ++$i }xeg