Is this what are you looking for?
my $countD = 0;
my $Dtimeout = 120;
my $DNOTComplete = 0;
eval {
local $SIG{ALRM} = sub { die "Timeout" }; # alarm handler
alarm($Dtimeout); # start alarm
# kernel will send us SIGALRM
# after $Dtimeout
while(<$log_DUT>) {
$fh_DUT->print($_);
last if m/standby handle h/;
$countD++;
}
alarm(0); # cancel alarm
};
if ($@ =~ /^Timeout/) {
# it was timeout
# handler called
# and died inside eval
$DNOTComplete = 1;
}