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;