Don't forget to use local $_ before while ( $_ = $reader->chunk ) {, or you might clobber something without even realizing it. For example, the following snippet replaces the content of @array with false values because $_ is (in turn) a reference to each element of @array:
foreach (@array) {
...
my $reader = ...;
...
while ($_ = $reader->chunk) {
...
}
...
}
The following dies with the run-time error "Modification of a read-only value attempted":
for ('a', 'b') {
...
my $reader = ...;
...
while ($_ = $reader->chunk) {
...
}
...
}