in reply to How to modify my regex?

Also, stop putting your regex pattern in a literal string. i.e. replace
my $regex = 'PATTERN'; s/$regex/.../;
with
s/PATTERN/.../;
or
my $regex = qr/PATTERN/; s/$regex/.../;
Otherwise you're soon going to run into the different quoting rules between literal strings and literal patterns; e.g. "\bfoo" and qr/\bfoo/ mean two different things.