in reply to Padding with \s

My favorite method uses pack:
$str = pack('A40',$str);
Note that this will truncate the string if it is longer than 40 characters.

--Jim