while() { my @columns; while(/("(?:\\\\|\\"|.)*?")| # "quoted" (\S+) # unquoted /gx) { my $match; if(defined $1) { # matched quoted $match = $1; $match =~ s/^"//; # remove opening " $match =~ s/"$//; # remove closing " } else { $match = $2; } $match =~ s#\\\\#\\#g; # \\ -> \ $match =~ s#\\"#"#g; # \" -> " push(@columns, $match); # store } print join('/', @columns), "\n"; } __DATA__ foo bar baz foo "bar \\ baz" "foo \"the bar\" baz" fü bär bäz