>perl -wMstrict -le "my $text = 'foo size=\"10\">HHili1 bar size=\"10\">HHili22 baz'; print qq{'$text'}; ;; $text =~ s/size=\"10\">HHili(\d{1,2})/size=\"10\" text-anchor=\"end\">HHili$1/g; print qq{'$text'}; ;; my $toxt = 'fee size=\"10\">HHili1 fie size=\"10\">HHili22 foe'; print qq{'$toxt'}; ;; my $pre = qr{ size=\"10\" }xms; my $post = qr{ >HHili\d{1,2} }xms; my $insert = ' text-anchor=\"end\"'; $toxt =~ s{ ($pre) ($post) }{$1$insert$2}xmsg; print qq{'$toxt'}; " 'foo size="10">HHili1 bar size="10">HHili22 baz' 'foo size="10" text-anchor="end">HHili1 bar size="10" text-anchor="end">HHili22 baz' 'fee size="10">HHili1 fie size="10">HHili22 foe' 'fee size="10" text-anchor="end">HHili1 fie size="10" text-anchor="end">HHili22 foe'