How can I quote a variable to use in a regex?

The Perl parser will expand $variable and @variable references in patterns unless the pattern delimiter is a single quote. Remember, too, that the right-hand side of a s/// substitution is considered a double-quoted string (see the perlop manpage for more details). Example:

        $string = "to die";
        $lhs = "die";
        $rhs = "sleep no more";
        
        $string =~ s/$lhs/$rhs/;
        # $string is now "to sleep no more"