in reply to Re: Question for regex experts
in thread Question for regex experts

... not restricted to a particular list of html codes ...

I'm not sure that's really such a good idea (it should be easy to get a list of all HTML entities you could possibly be interested in), but here's a generalization:

>perl -wMstrict -le "my $bad = 'x &foo;xx;yz;qwe; y &de;fghj;h; z &amp;&gt;&lt; y lt;gt; z'; print qq{'$bad'}; ;; my $tity = qr{ [[:alpha:]]+ ; }xms; ;; (my $fixed = $bad) =~ s{ (?: (?: \G (?<! \A)) | &) $tity \K (?= $tity) } '&'xmsg; print qq{'$fixed'}; " 'x &foo;xx;yz;qwe; y &de;fghj;h; z &amp;&gt;&lt; y lt;gt; z' 'x &foo;&xx;&yz;&qwe; y &de;&fghj;&h; z &amp;&gt;&lt; y lt;gt; z'