in reply to write command failing

The variables used in the format spec for the format directive and those used by write must be compiled into the same scope, or be visible in each other's. Just an idea, can't tell from the code you posted whether that's not the case.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'