use 5.012; use warnings; use Errno qw/EINTR EAGAIN/; # ... initialization stuff ... RECORD_LOOP: while (1) { my $record = ""; READ_LOOP: while (length($record) < 794) { my $_; given ($nh->read_entity(my $chunk, 794 - length($record))) { last RECORD_LOOP when ($_ == 0 and length($record) == 0); next READ_LOOP when ($_ ~~ [ undef, -1 ] and $! ~~ [ EINTR, EAGAIN ]); die "I/O error: $!" when ([ undef, -1 ]); die "Unexpected end of file" when (0); default { $record .= $chunk; } } } # ... record processing ... }