my $buf; my $read; while(($read = $s->read( $buf, 1024 )) > 0) { my $chunk = substr $buf, $read; # process chunk }