$escaped = qr/\\./; $quoted = qr/ (['"]) # start (?: $escaped | [^\1] )* # inside \1 # end, probably \g-1 better /x;