sub split_text { $_[0] =~ /("[^"]*"|[^\s"]+)/g; } my $text = 'The dog said "Hi, how are you?" I laughed.'; my @pieces = split_text($text); print "$_\n" for @pieces; __END__ The dog said "Hi, how are you?" I laughed.