$SIG{ALRM} = sub{die "timeout"}; eval{ alarm($timeout); $line_in = <$socket>; alarm(0); };