$_ = "test;a &lt;>amp;kap;&da;ma; & alfa&romeo & mich;"; while ( s/([&][^ ]*);(?!( |&|$))/\1AMPSEMICOLON/ ) {}; s/AMPSEMICOLON/;\&/g; # Output: test;a &<>&&kap;&da;&ma; & alfa&romeo & mich;