in reply to Re^2: When exactly do Perl regex's require a full match on a string?
in thread When exactly do Perl regex's require a full match on a string?

Here's the problem: With or without the /m modifier, the regex  /\n$\n/ does not match against the  "\n\n" string!
>perl -wMstrict -le "my $s = qq{\n\n}; print $s =~ /(\n$\n)/ ? qq{:$1:} : 'no match'; " no match >perl -wMstrict -le "my $s = qq{\n\n}; print $s =~ /(\n$\n)/m ? qq{:$1:} : 'no match'; " no match
The reason is that the  $\ sequence in the regex is taken as the  $\ 'output record separator' Perl special variable (a newline by default) and interpolated as such in the regex, which thus becomes equivalent to  / \n \n n /x (note the /x modifier).

If the regex is disambiguated as  / \n $ \n /x (again, note the /x modifier), the regex matches both with and without the /m modifier.

>perl -wMstrict -le "my $s = qq{\n\n}; print $s =~ /( \n $ \n )/x ? qq{:$1:} : 'no match'; " : : >perl -wMstrict -le "my $s = qq{\n\n}; print $s =~ /( \n $ \n )/xm ? qq{:$1:} : 'no match'; " : :
In many of the examples in other replies in this thread, the ambiguity of  $\ in a regex that arises from interpolation is not taken into account and causes (or can cause) confoosion.

Update: Consider the following misleading output from the OP:

string=<a\n> no modifier: regex=/^a$\n/ match => $ matches only boundary, \n matches newline [ ... ] m modifier (multi line mode): regex=/^a$\n/m match => $ matches only boundary, \n matches newline
In fact, neither regex matches:
>perl -wMstrict -le "my $s = qq{a\n}; print $s =~ /^a$\n/ ? ' ' : 'NO ', 'match'; print $s =~ /^a$\n/m ? ' ' : 'NO ', 'match'; " NO match NO match
The reason for the confusion is that the regex is first defined as  '^a$\n' (i.e., within non-interpolating single-quotes) in the test code, then interpolated within the actual  // regex operator, in which case the  $\ sequence is not ultimately interpolated as the output record separator string.

Again, after appropriate disambiguation, everything's fine:

>perl -wMstrict -le "my $s = qq{a\n}; print $s =~ /^ a $ \n/x ? ' ' : 'NO ', 'match'; print $s =~ /^ a $ \n/xm ? ' ' : 'NO ', 'match'; " match match