Jürgen Exner said:
I think there is quite some confusion about end-of-line, line end, the
dollar sign, and multi-line matches.
1: the dollar sign in a RE is only special if it is the last character in
the RE. In that case and only in that case it anchors(!) the RE to the end
of the string. It does not(!) match the newline character.
2: if you want to match a newline character then you will have to say so by
including the newline character in the RE: /word\n$var/
2: the m modifier allows an RE to expand across multiple lines within a
single string. However the given RE does not contain a \n or any wild card
that could match a \n. Therefore the m modifier is of no use in this RE.
Why then does "perldoc perlre" tell me this:
sion inside are listed below. Modifiers that alter the
way a regular expression is used by Perl are detailed in
"Regexp Quote-Like Operators" in perlop and "Gory details
of parsing quoted constructs" in perlop.
...
m Treat string as multiple lines. That is, change "^"
and "$" from matching the start or end of the string
to matching the start or end of any line anywhere
within the string.
...
does in any double-quoted string.) The "\A" and "\Z" are
just like "^" and "$", except that they won't match multi
ple times when the "/m" modifier is used, while "^" and
"$" will match at every internal line boundary. To match
the actual end of the string and not ignore an optional
trailing newline, use "\z".
You may be right in that a $ is only special at the end of the RE,
though, so I won't be able to match across line boundaries.
So the RE matches the text 'word' followed by the content of $var
interpreted as a RE.
Thanks,
Josef