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