while( read DATA, $data, BLOCKLEN ) { ## Extract the header from the front of the block my $header = substr $data, 0, BLOCKHDR, ''; ## do stuff with $header for my $cdr ( 1 .. MAXRECORD ) { ## Extract each record in turn from $data my $record = substr $data, 0, CDRLEN, ''; ## do stuff with $record } my $trailer = $data; ## Anything left in $data should be your trailer. ## do something with it. }