#!/usr/bin/env perl use 5.010; use strict; use warnings; my @test_strings = qw{""" "'" '"' ''' ""' "'' '"" ''"}; my $re = qr{ (?"|') (??{ "[^$+{FQ}]+" }) \k }x; for (@test_strings) { say "Testing [$_] : ", (/$re/ ? '' : 'no '), 'match.'; }