#!/usr/bin/perl use strict; use warnings; my $string = '0004$ADAM0002*330005LTESTL0005STESTS0005JTESTJ0005ZTESTZ'; my $currentpos = 0; while ($string) { my $recordlength = (substr $string, $currentpos, 4)+5; my $recordtype = substr $string, $currentpos+4, 1; my $fragment = substr $string, $currentpos+5, $recordlength-5; my $nextstartpos = $recordlength+1; print " string: $string\n"; print " record type: $recordtype\n"; print " data: $fragment\n"; print " tot record length: $recordlength\n"; print " next start pos: $nextstartpos\n"; my $currentpos = $currentpos + $recordlength+1 }