my $r; while ($r = read ...) { ... do stuff here ... } die "read failed: $!" unless defined $r;