in reply to Splitting long file

local $/="\$\n"; open(A, 'file'); while(<A>) { if (m/^(\w+)\n/) { #use whatever reges matches 'DATA' here open(my $fh, ">$1") or die "Couldn't open '$1' for write: $!"; print $fh $_; close $fh; } }
Add in some error checking, and you should be golden. This method has the advantage of only holding one chunk of data in memory at a time, so it scales well. Beware however that this will happily clobber files if there are two secions with the same header. To avoid that, open the output file for append ('>>' instead of '>').

thor