Well, something REALLY funky is going on due to the { } chars in the substring section of the $replace identifier.
You'll get a successful $replace if you switch { and } for $chr(123) and $chr(125) (only needed in the substring section).

Something like $eval({,0) works too but that's just too ugly if you ask me. ;P