my $counter = 0; $str =~ s/]*>\s*\s*[^<]*\K(?=<\/endtag3>)/sprintf " [ $c-%d]", ++$counter/egsi;