You should also enable warnings (and strictures; see strict), especially if you are a Perl novice. Consider your first regex with warnings enabled:
The Use of uninitialized value $. in regexp compilation... message gives you a clue about what is happening.c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $s = qq{aaa : AAA\n} . qq{bbb : BBB\n} . qq}ccc : CCC\n} ; print qq{[[$s]]}; ;; my $m = 'bbb'; ;; my $t = $s =~ s/.*^$m *: (.*?)$.*/$1/rsm ; ;; print qq{[[$t]]}; " [[aaa : AAA bbb : BBB ccc : CCC ]] Use of uninitialized value $. in regexp compilation at -e line 1. [[BBB ccc : CCC ]]
If the $ is unambiguously a regex metacharacter:
You have your intended output for this regex.c:\@Work\Perl\monks>perl -le "use warnings; use strict; ;; my $s = qq{aaa : AAA\n} . qq{bbb : BBB\n} . qq}ccc : CCC\n} ; print qq{[[$s]]}; ;; my $m = 'bbb'; ;; my $t = $s =~ s/.*^$m *: (.*?)$(?:.*)/$1/rsm ; ;; print qq{[[$t]]}; " [[aaa : AAA bbb : BBB ccc : CCC ]] [[BBB]]
Give a man a fish: <%-(-(-(-<
In reply to Re^3: Why multiline regex doesn't work?
by AnomalousMonk
in thread Why multiline regex doesn't work?
by nbd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |