$test=q|\AFZ\BJK \*\AFZ...*\ |; $new.=$1 while $test=~/([^\\]|\\\*.*?\*\\)/g; #### $test=q|\AFZ\BJK \*\A\*F*\Z...*\ |; $comment=qr/\\\*(?:[^\\]*|\\[^*]|(??{$comment}))*?\*\\/; $new.=$1 while $test=~/([^\\]|$comment)/g;