In What regular expressions can never match? /$./
was given as a response. I played around with that a bit, and discovered that the following two lines of code generate different output. The second matches, but the first does not. Can anyone explain why?
$ printf 'a\nb\n' | perl -0777 -ne 'print if m/$./m'
$ perl -0777 -e '$_="a\nb\n"; print if m/$./m'
Also, note that adding <> in the following causes the match to fail:
$ printf 'a\nb\n' | perl -0777 -e '$b = "a\nb\n"; say $b =~ m/$./m'
$ printf 'a\nb\n' | perl -0777 -e '$b = "a\nb\n"; <>; say $b =~ m/$./m'
(That is, the first prints '1', the second prints a blank line)