use Time::Out; my $retval = timeout 2 => affects { # some statement }; print $retval;