use threads; use threads::shared; use DBI; my $dbh = DBI->connect( ); ## Do stuff my $done :shared = 0; async { $dbh->ping while !$done and sleep 300; ## Adjust frequency to suit }->detach; ## system 'yourLongRunningCmd'; $done = 1; sleep 1; ## Thread disappears ## The rest of your script