By default, the . (dot) regex metacharacter matches everything except a newline. Use the /s modifier to make dot match everything.
See also \z for "absolute end of string" anchor.c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(pp); ;; for my $s (qq{yz}, qq{yz\n}) { $s =~ m{ (.) \z }xms; printf qq{in %s matched %s \n}, pp($s), pp($1); } " in "yz" matched "z" in "yz\n" matched "\n"
Update: You're also running into an interaction with $ which matches | which by default matches at "the end of the line (or before newline at the end)", so even with the /s modifier, the first position at which .$ can possibly match (scanning from left to right) is before a newline, if present; remember that the matching rule is leftmost longest.
Give a man a fish: <%-{-{-{-<
In reply to Re: How to match last character of string, even if it happens to be a newline?
by AnomalousMonk
in thread How to match last character of string, even if it happens to be a newline?
by Allasso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |