sub UCS2 { return join '', map { sprintf "%04X", ord } split //, $_[0] } print UCS2 ("Hello\x{1234}"); #### 00480065006C006C006F1234