Is the last line in your code meant to handle the case you're saying doesn't work in the main substitution? Well, sure the main one doesn't work, because /\\(.)/ doesn't match at the last character. It can't! $_ .= "\\" if /\\$/ is one way to do it -- no need for a length check at all.
By the way, "dereference" is usually understood to mean something else that what you are using it as here. The term you are looking for is probably "escape" or colloquially "backwhack".
In reply to Re: Regex to dereference
by gaal
in thread Regex to dereference
by Hena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |