title: How to escape dollar sign ($) in a string using perl regex
body: <p>I'm trying to escape several special characters in a given string using perl regex. It works fine for all characters except for the dollar sign. I tried the following:</p>
  
  <pre><code>my %special_characters;
  $special_characters{"_"} = "\\_";
  $special_characters{"$"} = "\\$";
  $special_characters{"{"} = "\\{";
  $special_characters{"}"} = "\\}";
  $special_characters{"#"} = "\\#";
  $special_characters{"%"} = "\\%";
  $special_characters{"&amp;"} = "\\&amp;";
  
  my $string = '$foobar';
  foreach my $char (keys %special_characters) {
    $string =~ s/$char/$special_characters{$char}/g;
  }
  print $string;
  </code></pre>