# $data has the required data and $sock is an open socket print $sock pack('N',length($data)) . $data . ("\0" x (4-(length($data)%4)));