Use /e to execute code to generate the substitution.
s{ cat }{ ++$i }xeg [download]
In reply to Re: Perl substitute with the nth match by ikegami in thread Perl substitute with the nth match by misterperl