in reply to find and replace counter

Another way to do it ;)

#!/usr/bin/perl use strict; use warnings; local $/; local $_ = <DATA>; my $c; s/(<xxx>)(?{++$c;})/<$c>$1/g; print; __DATA__ <xxx>fo</xxx> <p>ba</p> <xxx>foo</xxx><xxx>bar</xxx> <p>foobar</p>
Output:
<1><xxx>fo</xxx> <p>ba</p> <2><xxx>foo</xxx><3><xxx>bar</xxx> <p>foobar</p>

HTH,
PooLpi