I assume I
can make the first subexpression match zero or one time. In that
situation if the first subexpression doesn't match does $1=null?
...exactly (though it's 'undef', not null, strictly speaking). And
the nice thing is that Perl doesn't segfault or throw fatal exceptions
in such cases... it just works as expected. If used in a numeric
context, an undefined value will just evaluate to 0, which is typically
what you want.
So, the above s/// statement simply has to be modified as follows
s/^((\d+):)?(\d+):([\d.]+)/sprintf "%.3f", $2*60**2 + $3*60 + $4/e
as you may have figured out yourself in the meantime.