I assume, that you want to strip off a fixed size header first and then process a list of records having another fixed size. You can set the input record separator ($/) to a scalar reference holding the record size (see perlvar). Might be slower than (sys)read, though.
#!/usr/bin/perl
use strict;
use Data::Dumper;
my ($n, $m) = (9, 3); # var-names as requested
my @result;
$/ = \$n; # record size := 9 characters
$result[0] = <DATA>; # read one record (size: 9)
$/ = \$m; # record size := 3 charcters
while (<DATA>) {
# do something with the next block of 3 chars
last if length != $m; # stop at first non m-sized record
push @result, $_;
}
print Dumper \@result;
__END__
123456789111222333444555666777888999xxxyyyzzzZ
This prints:
$VAR1 = [
'123456789',
'111',
...
'zzz'
];
|