$month =~ s/^(\d)$/0$1/; # adds leading zero if there is just a single # digit- otherwise has no effect # *** I recommend this idea for # your application. **** $month = sprintf("%02d", $month); # re-assigns a new string value # to $month no matter what