in reply to Regular Expression

Your pattern, /(\d)/ just means "match a single digit character," which will match the first digit in any number, regardless of length. If you wanted to do this with a regex, you could say,

if ($month =~ /^\d$/) { $month = '0' . $month; }

Note that there is no need to capture the match with parentheses. This is a bit overkill for simply formating a number, though. Why not just use sprintf?

$month = sprintf("%02d", $month);

Update: Corrected typo.