my $start = time(); while (time()-$start <20 ){ ... Programmbereich .... } exit;