use warnings; use strict; MAIN: { my $sq = q{'}; my $dq = q{"}; my $sq_body = qr{ [^\\$sq]* (?: \\. [^\\$sq]* )* }xms; my $dq_body = qr{ [^\\$dq]* (?: \\. [^\\$dq]* )* }xms; my $text = do { local $/; }; # slurp all text my @quotes = grep defined && length, # ignore empty captures, null strings $text =~ m{ $dq ($dq_body) $dq | $sq ($sq_body) $sq }xmsg; s{ \n }{ }xmsg for @quotes; # make multi-line quotes into one line print "<$_> \n" for @quotes; } __DATA__ "Mary had a little lamb", she said. She thought, "I'm sure he said 'Wait a tick' before". She wondered, "What happens to an escaped \"?" Also, what happens to a "" or '' null quote? Nobody loves me 'Mary had a large and "wooly" lamb' Do not divide by '0'. Don't divide by '0'. She said, 'I'm sure it'll be ok.' #### <0> <. She said, >