in reply to sprintf to zero-pad on the right

How about $string.="0" x (8-length($string))