see
matching comments, It has detailed code to do
exactly this. Just replace the comments flags
$start and $end with '"' for both of them.
This (slightly modified from
merlyn's answer
here)
will work and is really fast:
open(FILE, "test.txt") || die;
{
local $/ = undef; #set to 'slurp' mode
$file = <FILE>; #read entire file into $file
}
close FILE;
$start = '"';
$end = '"';
my $inside = 0;
my $oldpos = 0;
while ($file =~ /(?<!\\)(\Q$start\E|\Q$end\E)/g) {
if ($inside == 0) {
$oldpos = pos($file) - length($start);
$inside++;
} else {
print substr($file, $oldpos, pos($file)-$oldpos);
$inside--;
}
}