7d. Regex relative backrefs 

my $text = <<EOF;
It is a "faux pas" to 'mind meld'
EOF

my $word   = '\b[\w\']+?\b';
my $phrase = '([\'"]).*?\g{-1}';

$text =~ s/($phrase|$word)/[$1]/g;

say $text;
[It] [is] [a] ["faux pas"] [to] ['mind meld']