$possibly_safe = "^!|~¦¡£\0"; $mystery_str = '$a !~ qr^some|thing^'; eval "(\$safe = \$possibly_safe) =~ tr/$mystery_str//d"; print $safe; # "¦¡£\0"