sub quoted_string { my $type = quotemeta shift; return qr/ $type (?: [^$type]+ | (?<= \\ ) $type )* $type /x; } my $data = qq(This "is a quoted string" and so is "this" and this one "has \\\\ \\" backslashes" and other unrelated stuff); my @matches = $data =~ / ((??{ quoted_string( qq(") ) })) /xg; print join("\n\n",@matches);