#!/usr/bin/perl use strict; use warnings; my $run_limit_hours = 9; # You would of course grab this from @ARGV or something my $start_time = time; # Number of seconds since epoch my $end_time = # Deadline -- end time in seconds-since-epoch $start_time + $run_limit_hours * 60 * 60; # 60 seconds per minute, 60 minutes per hour while (1) { my $current_time = time; if ($current_time > $end_time) { last; } &doTheThing(); } exit;