http://www.perlmonks.org?node_id=557548


in reply to Counting the number of replaces

In the spirit of TIMTOWTDI:
s/<I>/$count++;"<italic>"/eg; print $count || 0;
No, I didn't say it was pretty. ;-)