local $/ = \128; while (<$fh>) { ... $_ contains 128 bytes ... } #### while (length($str)) { my $rec = substr($str, 0, 128, ''); ... $rec contains 128 bytes ... }