This seems to work:
$test ="\\AFZ\\BJK \\\*\\AFZ...\*\\";
$span = 0; # Span is a span counter
foreach( split(/(\\\*|\*\\)/,$test) ){ # Split on spans keeping the co
+mmenttags
if($_ eq '\\*'){ # See if its a comment-start
$span ++;
} elsif($_ eq '*\\'){ # if it's a comment-end
$span --;
} elsif($span eq 0){ # Only if not in comment
$_=~s/\\//igs;
}
$newtest.=$_;
}
Edited: Made an elsif instead of several ifs.
Edited: I got a negative vote, i guess because the lack of comment. I found the question a challenge for myself, but i forgot to share the thoughts. Therefor more comment added.