my $start = $format->parse_datetime(...); my $stop = $format->parse_datetime(...); $start = $min_start if $start < $min_start; $stop = $max_stop if $stop >= $max_stop; my $dur = $start->delta_ms($stop); printf("%d minutes and %d seconds\n", $dur->in_units(qw( minutes seconds ));