#! perl -slw use strict; require 5.008; sub make_dequote_rx { my @char = map quotemeta, @_; my $chars = join '', @char; my $rx = join( '|', map(qq[$_ (?: \\ . | $_$_ | [^$_] ) + $_], @char), qq[(?: \\ . | [^$chars] ) +], ); return qr/\G ( $rx )/x; ##You cannot apply /g to qr// } my $dequote = make_dequote_rx qw(' "); #" while( ){ chomp; our $quoted; print; print "\t<$1>" while m[$dequote]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 #### D:\Perl\test>junk 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 <"like"" quotes"> < unquoted stuff> unquoted stuff 'quoted stuff with embedded ''like'' quotes' unquoted stuff <'like'' quotes'> < unquoted stuff> unquoted stuff "quoted stuff with embedded """"like"""" quotes" unquoted stuff <"""like"""" quotes"> < unquoted stuff> unquoted stuff 'quoted stuff with embedded ''''like'''' quotes' unquoted stuff <'''like'''' quotes'> < unquoted stuff> unquoted stuff "quoted 'stuff' with escaped \"like\" quotes" unquoted stuff unquoted stuff 'quoted 'stuff' with escaped \'like\' quotes' unquoted stuff <' with escaped \'> <' quotes'> < unquoted stuff> unquoted stuff "quoted stuff with embedded ""like"" quotes and escaped \"like\" quotes" unquoted stuff <"like"" quotes and escaped \"> <" quotes"> < unquoted stuff> unquoted stuff 'quoted stuff with embedded ''like'' quotes and escaped \'like\' quotes' unquoted stuff <'like'' quotes and escaped \'> <' quotes'> < unquoted stuff>