#!/usr/bin/perl use strict; use warnings; #Open data file and put it into variable open FILE, " }; #Set offset if there is a header record and add it to initial position my $offset = 0; my $currentpos = 0 + $offset; #Set lastpos = length of data my $lastpos = length($string); #Read until end of data while ($currentpos < $lastpos) { #Grab record length within data my $recordlength = (substr $string, $currentpos, 4); #Grab record type which is 5th char my $recordtype = substr $string, $currentpos+4, 1; #Using record length grab the record and put it into variable my $fragment = substr $string, $currentpos, $recordlength; #Calculate starting position for next record .. not used at present my $nextstartpos = $currentpos + $recordlength + 1; #Use if clause to identify only $ record types and print the record data if ($recordtype eq '$') { print " record type: $recordtype\n"; print " data: $fragment\n"; #Inrement starting position for the next loop $currentpos = $currentpos + $recordlength; } }