use IO::Socket; my $sock = new IO::Socket::INET("$remote_server:43") || die $!; my $n = 5; # do this 5 times every 12 hours while (1) # loop forever { my $time = time(); # keep track of when we start print $sock "$data\r\n"; my @output = <$sock>; $output = join('', @output); if ($output =~ /$no_match/gi) { &true; } else { &false; } # sleep for the PERIOD, minus the DURATION sleep( int(43200 / $n) - ( time() - $time) ); }