in reply to scalar number with preceding 0.

If I run the code you posted verbatim, except for removing the ..., I get 0905 in the first line. The problem in your code is elsewhere, either in that ... which you're hiding, or in another part completely.

Why would you think a zero character magically turns into a space? Are you sure a zero character was ever added? Try instrumenting your code:

sub format_time{ my ( $h, $m, $s ) = @_; ... warn "\$h is now '$h', length " . length $h; if ( length( $h ) < 2 ) { warn "going to pad with zero"; $h = "0" . $h; } if ( length( $m ) < 2 ) { $m = "0" . $m; } return $h . $m . $s2; }

I am almost certain you will find that the space is already there by the time you get to that conditional and that the second message from inside that code block never gets printed.

Always question your assumptions, and know what your code is doing, instead of programming by coincidence.

And then, when you've found the problem and taken away its lesson, throw away your code and use sprintf.

Makeshifts last the longest.