while (<>) { ... $! = undef; } if (defined($!)) { # $! contains error from last close