in reply to Matching brackets in Regular Expression

You can use quotemeta function or \Q .. \E in your regular expression -
if ($text =~ /.*\Q$stub\E.*/s) { #do something }
Updated: I thought it might be useful for you to have a read of the perlre documentation on CPAN here. Look for quotemeta.