use strict; use warnings; use Text::ParseWords; while () { chomp; my @fields = m/\s* ("(?:(?!(?", join ('<, >', @fields), "<\n"; print ">", join ('<, >', @words), "<\n\n"; } __DATA__ two words "and a \"quoted\" string" two words 'and a \'quoted\' string' #### >two<, >words<, >"and a \"quoted\" string"< >two<, >words<, >and a "quoted" string< >two<, >words<, >'and a \'quoted\' string'< >two<, >words<, >and a \'quoted\' string<