$s = 'foo bar'; $bytesequenz = pack('N', length $s).$s;