#! perl -slw use strict; require 5.008; my $re_quoted = qr[ (["']) #'" (?{ local $q = $^N }) ( (??{ "(?x: [^$q] | (?: (? ){ chomp; our $quoted; print; print "\t<$quoted>" while m[$re_quoted]g; print ''; } __DATA__ unquoted stuff "quoted stuff" unquoted stuff unquoted stuff 'quoted stuff' unquoted stuff unquoted stuff "quoted stuff with embedded 'alternate' quotes" unquoted stuff unquoted stuff 'quoted stuff with embedded "alternate" quotes' unquoted stuff unquoted stuff "quoted stuff with embedded ""like"" quotes" unquoted stuff unquoted stuff 'quoted stuff with embedded ''like'' quotes' unquoted stuff unquoted stuff "quoted stuff with embedded """"like"""" quotes" unquoted stuff unquoted stuff 'quoted stuff with embedded ''''like'''' quotes' unquoted stuff unquoted stuff "quoted 'stuff' with escaped \"like\" quotes" unquoted stuff unquoted stuff 'quoted 'stuff' with escaped \'like\' quotes' unquoted stuff unquoted stuff "quoted stuff with embedded ""like"" quotes and escaped \"like\" quotes" unquoted stuff unquoted stuff 'quoted stuff with embedded ''like'' quotes and escaped \'like\' quotes' unquoted stuff