use strict; use warnings; my $scary_regex = shift; $scary_regex =~ tr/\cA//d; # There are now no control-As in the string, # so I can safely use them as delimiters my $safe_pat = eval "qq\cA$scary_regex\cA"; my $safe_reg = qr/$safe_pat/; print "Safe pat is $safe_pat; reg is $safe_reg\n";