$ perl -le " for( @ARGV ){ print; s{(.)}{$1.++$counter}ge; print} " abc XYZ abc a1b2c3 XYZ X4Y5Z6 ## perl -pTe "s{(core:para edpnum-start=\x22)}{$1.++$counter}ge; " < test.xml > testcounted.xml ## perl -pi.orig -Te "s{(core:para edpnum-start=\x22)}{$1.++$counter}ge; " test.xml ## diff -u test.orig test.xml