$length_of_u = length($u); # how long is this string? $how_many_characters_short = 6-$length_of_u; # how far are we from having 6 characters? $padding = '0' x $how_many_characters_short; # this will give us as many 0's as $how_many_characters_short is long (e.g. if it is 4 - it gives us '0000') $u = $padding.$u; # concatenate them together... finished!