#!/usr/bin/perl -w use strict; use warnings; print time_to_string(1234), "\n"; print time_to_string(12345), "\n"; print time_to_string(123456), "\n"; sub time_to_string { my $t = shift; # t=total time in seconds my $seconds = $t % 60; $t=($t-$seconds)/60; # t now has minutes my $minutes = $t % 60; $t=($t-$minutes)/60; # t now has hours my $hours = $t % 24; $t=($t-$hours) /24; # t now has days my $str = ''; $str .= "$t days, " if $t>0; $str .= sprintf "% 2u:% 2u:% 2u", $hours, $minutes, $seconds; } #### roboticus@Boink:~$ ./848005.pl 0:20:34 3:25:45 1 days, 10:17:36 roboticus@Boink:~$