# $special_characters_escaped = backslash( $source_string ); sub backslash ($) { local $_ = ( defined $_[0] ? $_[0] : '' ); # Preserve only printable ASCII characters other than \, ", $, and @ s/([^\x20\x21\x24\x25-\x39\x41-\x5b\x5d-\x7e])/\\$Backslashed{$1}/gs; return $_; }