in reply to quoting characters

This seems to do the trick:

s/(\\*)(#[^#\\]*)/length($1)?length($1)%2?"$1$2":$1:""/eg;

And hear it is again, in a more readable form:

s/(\\*)(#[^#\\]*)/ ## Matching anything before a pound sign, putting (back)slashes (or la +ck thereof) into $1. ## Also make sure that we do not grab any slashes and pounds after the + first pound { if (length($1)) { ## If we found some backslashes if (length($1)%2) ## If there are an odd number of backslashes print "$1$2"; ## Return all slashes and pound - this is not a true + comment } else { print $1; } ## Even number - return only the slashes } else { print ""; } ## Return nothing, this is a comment } /eg;