It appears as if the regex is compiled to take the \\ to mean \ but compares against the string which keeps the original \\.
No. The backwhack acts as an escape character in strings and the details can get confusing.
The original text in your case only has one literal backwhack, not two. Print it to see for yourself.
In the first example your $match variable has one literal backwhack but once that pattern is used, it looks like "\w" which matches a word character in a regex.
In the second example, the first backwhack in the pattern escapes the second resulting in one actual backwhack. That one matches the one in your original text.
To get around these issues, learn how escaping works in strings and patterns. Perl's quotemeta() function can help a great deal in many situations and, in patterns, the special escapes \Q and \E are useful.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: using a scalar in a regex with backslashes
by sauoq
in thread using a scalar in a regex with backslashes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |