Am I overlooking something or could your sprintf statements be written much simpler like this?
$res .= sprintf "%dw", $weeks if $weeks;
$res .= sprintf "%dd", $days if $days;
$res .= sprintf "%dh", $hours if $hours;
$res .= sprintf "%dm", $minutes if $minutes;
$res .= sprintf '%ds', $seconds;
Update: That was changed a little bit too much, as grinder correctly remarked ... nevertheless, my main concern were those ugly string interpolations, and I think this works:
$res .= sprintf "%dw", $weeks if $we
+eks;
$res .= sprintf "%dd", $days if $days or $we
+eks;
$res .= sprintf "%dh", $hours if $hours or $days or $we
+eks;
$res .= sprintf "%dm", $minutes if $minutes or $hours or $days or $we
+eks;
$res .= sprintf '%ds', $seconds;
-- Hofmator