use Text::ParseWords; $_ ='1111 "222 222" 333 4444 55 666 77777'; print join(",", (quotewords('\s+', 0, $_))[0,1,2,4,5,6]);