#!/usr/bin/perl $file = shift; exit if (!$file); open(IN,$file); $count = 0; while() { if (/^\n$/) { if ($text) { writeout(); $count++; $text = 0; $chunk = ''; } } else { $text = 1; $chunk .= $_; } } writeout(); sub writeout { $ofile = "000" . $count . ".txt" if ($count < 10); $ofile = "00" . $count . ".txt" if (($count >= 10) && ($count < 100)); $ofile = "0" . $count . ".txt" if (($count >= 100) && ($count < 1000)); $ofile = $count . ".txt" if (($count >= 1000)); open(OUT,">",$ofile); print OUT $chunk,"\n"; close(OUT); }