/m
and /s
both affect how the match operator treats multi-line strings.
With the /m
modifier, ^
and $
match the beginning and end of any line within the string. Without the /m
modifier, ^
and $
just match the beginning and end of the string.
Example:
$_ = "foo\nbar\n";
/foo$/, /^bar/ do not match
/foo$/m, /^bar/m match
With the /s
modifier, the special character .
matches all characters including newlines. Without the /s
modifier, .
matches all characters except newlines.
$_ = "cat\ndog\ngoldfish";
/cat.*fish/ does not match
/cat.*fish/s matches
It is possible to use /sm
modifiers together.
$_ = "100\n101\n102\n103\n104\n105\n";
/^102.*104$/ does not match
/^102.*104$/s does not match
/^102.*104$/m does not match
/^102.*104$/sm matches