my @a = ( 'simple', 'keep simple', 'a "bit more" difficult', 'an "increasing more" "and more" here'); foreach $_ (@a) { s/ (?=("[^"]*"[^"])*[^"]+$)/ | /g; print "$_\n"; } #### simple keep | simple a | "bit more" | difficult an | "increasing more" | "and more" | here