in reply to Perl socket programming
Yes, pack can do that. Take a look at perlpacktut in the manpages or pack in perlfunc.