Borodin's regex will work for the examples from this lab assignment.
However, it's also possible for a backslash to escape itself. This comes up when one includes windows paths in a string, so the following regex would catch that case:
use warnings;
use strict;
use 5.012;
my $file = do { local $/; };
my @strings = $file =~ /"(?:(?>[^"\\]+)|\\.)*"/g;
say "<$_>" for @strings;
__DATA__
"This is string"
"1!=2"
"This is \"string\""
"string1"."string2"
"String"
"S
t
r
i
n
g"
"C:\\windows\\style\\path\\"
"another string"
Outputs:
<"This is string">
<"1!=2">
<"This is \"string\"">
<"string1">
<"string2">
<"String">
<"S
t
r
i
n
g">
<"C:\\windows\\style\\path\\">
<"another string">
For a quick explanation of the pattern:
my @strings = $file =~ m{
"
(?:
(?> # Independent subexpression (reduces backtracking)
[^"\\]+ # Gobble all non double quotes and backslashes
)
|
\\. # Backslash followed by any character
)*
"
}xg; # /x modifier allows whitespace and comments.