#!perl while () { chomp; print "for [$_]:\n"; # split on XX, but only when it's not in # single quotes. while (m% ([^']*? # Some unquoted stuff (?:'[^']*' # optionally, quoted followed by [^']*?)*? )# unquoted stuff. non-greedy XX | # field separator, or (.+) %xg) # a non-blank final field { # field value should now be in defined($2)?$2:$1 my ($t1, $t2) = qw(undef undef); $t1 = "[$1]" if defined($1); $t2 = "[$2]" if defined($2); print "\t$t1\t$t2\n"; } } __END__ aXXbXXc abcd a little 'quote XX' quote stuff XX other