Please see these simple commands:
$ echo $tmp UY\\U[_ $ echo \"a\" | sed \"s|a|${tmp}|g\" UY[_
The \\U is eaten. Other backslashes
\\U
You could reparse $tmp itself through sed
echo "a" | sed "s|a|$(echo ${tmp} | sed 's|\\|\\\\|g')|g"