while ( m/ (?: # non-capturing braces "(?[^"]*)" # Find either string delimited by '"' | # or (?[^,]*) # string up to next ',' ) (?:,|$) # After which there is either , or end of line /gx ) { push @input, $+{val}; }