eval { local $SIG{ALRM} = sub { die "timeout" }; alarm 10; $input = ; alarm 0; }; if ($@ and $@ =~ /timeout/) { print "Reading timed out"; } elsif ($@) { die "Other error: $@"; }