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.
Comment on Re^2: Passing a structure from C to Perl
Corion suggested at least three possible data file formats. You suggest existing libraries for C. Perhaps you could elaborate on the pros and cons of some libraries on both the Perl and C sides for the given formats to help the OP make the best choice.