use strict; use warnings; my $string = 'one two "three" four "five" six'; my (@quoted,@unquoted); my $length = 0; while ( $string =~ /\G\s*(?:("[^"]+")|([^"\s]+))(?:\s+)?/g ) { if ( $1 ) { push @quoted,$1 } else { push @unquoted,$2 } $length = pos $string; } unless ( length($string) == $length ) { print "Quotes did not match" } else { local $\ ="\n"; print q(@quoted:), join ",", @quoted; print q(@unquoted:),join ",",@unquoted; } #### use strict; use warnings; my $string = ' one two "three" four "five" six'; my (@quoted,@unquoted); $\ ="\n"; 1 while ( $string =~ s/"([^"]+)"/push @quoted,$1;''/ge ); if ( $string =~ /"/ ) { print q(A " was found so failure) and exit; } push @unquoted, split " ", $string; print q(@quoted:), join ",", @quoted; print q(@unquoted:),join ",",@unquoted;