And on both the "C" and the Perl side use well-tested existing libraries to do the encoding and decoding for you. Of course it is a little more involved on the C side but there do exist utilities that can munch a struct definition or a header-file and "compile" it into a subroutine that will quickly encode or decode that structure.