How to find the count and replace the particular part of string in perl?

Hi,

I am taking the current time using localtime function in perl. For example if the time is:

#Using localtime

$time = "12:3:10";

I have to replace the value 3 (03) i.e second position to be 03.

The output should be:

12:03:10

But if the other string for example:

$str: "12:45:90";

The above code should not get replaced i.e 45 should not be 045.

The output should be:

12:45:90

How to get the above outputs?

The string should get replaced only if second position is single (3 to 03) otherwise not.

How to do the replacements in perl?

Regards

$time=~s/:(.):/:0\1:/;