undef $/; $_=<>; while ( s/={10,}(\n.*?\n)(={10,}\n)/$2/s ) { push(@myblocks,$1); } print "I counted ".scalar(@myblocks)." blocks\n"; while ( $myblock=shift(@myblocks) ) { open( OUT, ">$myname" . $i++); print OUT $myblock; close OUT; }