The documentation that you associate with me seems very understandable to me. This would help if you explained what the problem was with understanding, and how you came to the conclusion that /s and /m are opposites.
In short, /s changes the behavior of the point metacharacter . so that it matches any character in general. Usually it matches anything other than the newline "\n" , and therefore treats the line as a string s , even if it contains newline characters.
/m changes the carriage ^ and dollar $ metacharacters to match the newline characters within the line, treating it as line m . Usually they will only match at the beginning and end of the line.
You should not be confused with the /g modifier, which is greedy. This is for g lobal matches that will find all occurrences of the pattern inside the string. The term βgreedyβ is usually the user for the behavior of quantifiers in a pattern. For example,. .*? called greedy because it will match as many characters as possible, unlike .*? which will match as few characters as possible.
Update
In the modified question, you use /".*"/mg , in which /m does not matter, since, as noted above, the modifier only changes the behavior of the $ and ^ metacharacters, and they are not in your template.
Changing it to /".*"/sg slightly improves the situation when . can now match a new line at the end of each line, and therefore the pattern can match multi-line lines. (Note that here the line of the object is considered to be "one line", that is, Coincidence behaves as if there were no lines in the new line, if it comes to . ). This is the traditional meaning of greedy, because the pattern now matches all values ββfrom the first double quote in the first line to the last double quote at the end of the last line. I guess this is not what you want.
There are several ways to fix this. I recommend changing your template so that the desired string is a double quote, followed by any sequence of characters except double quotes, followed by another double quote. It is written /"[^"]*"/g (note that the /s modifier is no longer needed since there are no dots in the template) and it almost does what you want, except that escaped double quotes are considered as the end of the template.
Take a look at this program and its output, noting that I put chevron >> at the beginning of each match so that they can be distinguished
use strict; use warnings; my $file = do { local $/; <DATA>; }; my @strings = $file =~ /"[^"]*"/g; print ">> $_\n\n", for @strings; __DATA__ "This is string" "1!=2" "This is \"string\"" "string1"."string2" "String" "S t r i n g"
Exit
>> "This is string" >> "1!=2" >> "This is \" >> "" >> "string1" >> "string2" >> "String" >> "S t r i n g"
As you can see, everything is in order, except that two matches were found in "This is \"string\"" , "This is \" and "" . A fix that may be harder than you want, but it is possible. Please tell me if you need this too.
Update
I can also finish this. To ignore escaped double quotes and consider them as part of a string, we need to accept either \" or any character other than double quotes. This is done using the regex operator | and it must be grouped inside non-capturing parentheses (?: ... ) . The end result is /"(?:\\"|[^"])*"/g (the backslash itself must be escaped, so it doubles), which when entered into the above program produces this output, which , as I suppose, is that you wanted.
>> "This is string" >> "1!=2" >> "This is \"string\"" >> "string1" >> "string2" >> "String" >> "S t r i n g"