use strict; use warnings; #I made my variables more semantic. @times was just to general, %durations is a better word, thanks to those who used it. :) my %durations = ( 's1' => [qw(3:58 2:48 4:28 5:06 6:50 5:33 4:05 3:29 4:48 6:19)], 's2' => [qw(5:33 5:08 5:30 6:52 6:56 6:48 6:34 5:43 6:50 8:32 6:22 8:39)], 's3' => [qw(5:21 8:01 5:37 7:19 5:46 7:44 6:43 7:17 8:02 6:50 7:54 8:44)], ); # %durations are minutes and seconds. sub get_duration { my ($var) = @_; my $total_seconds; for my $duration (@{$durations{$var}}) { my ($minutes,$seconds) = split(':',$duration); # The change here made the line much easier to read. :) $total_seconds += ($minutes * 60) + $seconds; # This eliminated my need to create another array then adding the values of that array. :) } my $total_minutes = int($total_seconds/60); #I totally forgot about int. :S my $total_hours = int($total_minutes/60); my $print_seconds = $total_seconds % 60; my $print_minutes = $total_minutes % 60; return $total_hours.':'.$print_minutes.':'.$print_seconds."\n"; } print get_duration('s1'); print get_duration('s2'); print get_duration('s3');