Let us look at Perl code and result:
$s = "a\nb\nc\n";
$s =~ s/^b/X/;
print $s;
a
b
c
$s = "a\nb\nc\n";
$s =~ s/^b/X/m;
print $s;
a
X
c
I think Perl is right, ^ matches the position after new line in the middle only when multiline is enabled.
Let us look at Ruby:
$s = "a\nb\nc\n"
print $s.sub(/^b/,'X')
a
X
c
$s = "a\nb\nc\n"
print $s.sub(/^b/m,'X')
a
X
c
The ^ matches the position after newline in the middle of text regardless if it is in multiline mode or not.
For the life of me, I cannot find Ruby documentation which defines what the multiline option will do, where is it?
Also Ruby has no Single line mode (s)?
undefined group option: /(?s)^b/
/^b./s
will parse but it does not behave like Perl (. matches new line).
PS: I tested using Perl 5 and Ruby 3.0.