in reply to Regex help

If you would have just used qr, you wouldn't have had this problem. Plus, Perl would have checked for you if $pattern actually contains a valid regex on its own, and not just test on the larger pattern.
my $pattern = qr/AB/;
or
my $pattern = "AB"; $pattern = qr/$pattern/;
It also incorporates regex switches into the regex, so you can't globally override them. For example, if $pattern looks like "A B", if you use it in /$pattern/x, the space would be stripped from the subpattern. But not with qr.