in reply to Re^2: Regex to dereference
in thread Regex to dereference

Ah, then you need what's called a zero-width negative look-behind.

$str =~ s/(?<!\\)\\$/\\\\/; # match a backslash at the EOL # that isn't preceded by a backslash

See perlre for more stuff like this.