my $re = qr/ (?['"]) # Capture starting quote. (? # Capture content. (?: (?>[^'"]*) # Match non-quotes, don't backtrack. (?(?!\k).) # Match opposite quote. )* # Repeat. ) \k # Match ending quote. /x;