in reply to Got's to be a better way

Have a look at printf and sprintf. They'll take care of your padding. Have a look at this example from perldoc -f sprintf

# Format number with up to 8 leading zeroes $result = sprintf("%08d", $number);