Have you tried using a character class?
$dir =~ s/([\[\]{}~*?])/\\$1/g; [download]
In reply to Re: Faster way to regex this by hdb in thread Faster way to regex this by jar00n