#!/usr/bin/perl use warnings; use strict; use LWP::Online 'online'; my $start = time(); my $now = 0; my $max = 30; my $conn = 0; while ($now < $max) { if ( online('http') ) { $conn = 1; last; } sleep(1); $now = time() - $start; } die "$max seconds over. No connection. Aborting.\n" unless $conn;