in reply to Avoid recursive replacement using regex

Hello anirudhkumar_r,

Update: parv’s solution is simpler, therefore better!

To prevent recursive replacement, you can use negative look-behind assertions as follows:

#! perl use strict; use warnings; my $s = '&amp;lt; &lt; &amp;xyz &amp;gt;abc 123&gt;456 me&amp;you'; $s =~ s/ (?<!&amp;) &lt; /</gx; $s =~ s/ (?<!&amp;) &gt; />/gx; $s =~ s/ &amp;lt; /&lt;/gx; $s =~ s/ &amp;gt; /&gt;/gx; $s =~ s/ &amp; /&/gx; print $s;

Output:

22:03 >perl 1084_SoPW.pl &lt; < &xyz &gt;abc 123>456 me&you 22:03 >

See “Look-Around Assertions” in perlre#Extended-Patterns.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,