in reply to Problem in String Replacement

With the example input data you gave us, nothing much happens, neither do <ce:label> tags get added, nor does the code loop forever. So we can only guess what happens with your real data.

My guess is that it is related to the fact that you conduct two matches/substitutions on the same string; the substitution might reset pos, so that the match starts from the beginning again.

Update:

Here's a short demonstration of what the problem might be:

use strict; use warnings; my $str = 'aa'; while ($str =~ /a/g) { $str =~ s/a/ba/g; print $str, "\n"; last if length($str)> 10; }

Without the last if..., this would loop infinitely. A possible fix is to look only for a's that don't come before a b:

while ($str =~ /(?<!b)a/g) { ...