# this requires $username < 16 bytes and prefix packs with spaces sprintf '%16s', $username; # this will give you a data length divisible by 16 for any length # we use null byte prefix packing sub get16 { my $data = shift; return "\0" x ( 16 - length($data)%16 ) . $data; }