in reply to Parsing a long string

The original post was unclear what the intent was for the string. That being said, it would seem that setting $/ (the input record separator) to "1START" would make the data easier to handle.

test.dat:
1START ACCOUNTA XXXXXMA 12345 XYZ111 1START +ACCOUNTB XXXXXBR 12345 XYZ191 1START ACCOUNTA + XXXXXNY 54321 XYZ131
code:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $| = 1; srand(); $Data::Dumper::Sortkeys = 1; my $fn = q{test.dat}; open my $df, $fn or die $!; $/ = q{1START}; while ( my $line = <$df> ) { chomp $line; next if ( $line =~ m/^\s*$/ ); if ( substr( $line, 3, 8 ) eq q{ACCOUNTA} ) { print $/, $line, qq{\n}; } } close $df;
output:
1START ACCOUNTA XXXXXMA 12345 XYZ111 1START ACCOUNTA XXXXXNY 54321 XYZ131

Hope that helps.