while () { chomp; my $q = 0; # documented for the faint of heart my @fields = split m{ ' # if we match a ' (?{ $q = !$q }) # toggle $q (?!) # and fail (don't split here) | # OR XX # if we match XX (?(?{$q}) # and $q is true (?!) # fail (don't split here) ) # otherwise it succeeds and splits }x; print "[", join("][", @fields), "]\n"; }