use strict; use warnings; my $string = 'This is "the search" string "that was" supplied'; my @quotes; while( $string =~ s["(.*?)"][] ) { push( @quotes, $1 ); } my @keys = split( ' ', $string ); use Data::Dumper; print "Quotes:\n", Dumper( \@quotes ); print "Keys:\n", Dumper( \@keys ); output: Quotes: $VAR1 = [ 'the search', 'that was' ]; Keys: $VAR1 = [ 'This', 'is', 'string', 'supplied' ];