http://www.perlmonks.org?node_id=1032548


in reply to Sending raw hex in UDP packets

Even though the pack function can be a bit hard to grok from the documentation, it seems like a more "intuitive" approach in this sort of case (or, at least it would, if anything about "pack" were intuitive...)
perl -e 'for $i (1..3) { print pack( "C*", 0x21, $i, 0x55 ) }' | xxd - +g 1 0000000: 21 01 55 21 02 55 21 03 55 !.U!.U!.U
(UPDATE: In case it helps, remember that there's also the ample "tutorial" man page for pack: perlpacktut)