$foo = qq{^snafu^|^foobar^\n};
$foo =~ m/\A(\W) # \A instead of ^ and match first non-word
.+? # +? Minimal match everything that isn't in \1
\1(\W) # Match non-word following the 2nd \1
/xms;
$TEXT_QUAL = $1;
$FIELD_SEP = $2;
####
$foo =~ /\G$TEXT_QUAL(.*?)$TEXT_QUAL[$FIELD_SEP\n]/xmsgc;
####
$foo =~ /\G\$TEXT_QUAL(.*?)\$TEXT_QUAL[\$FIELD_SEP\n]/xmsgc;
####
$foo =~ /\G\\$TEXT_QUAL(.*?)\\$TEXT_QUAL[\\$FIELD_SEP\n]/xmsgc;
####
$LIT_TEXT_QUAL = qq{\\$TEXT_QUAL};
$LIT_FIELD_SEP = qq{\\$FIELD_SEP};
$foo =~ /\G$LIT_TEXT_QUAL(.*?)$LIT_TEXT_QUAL[$LIT_FIELD_SEP\n]/xmsgc;