#Include the newline in the delimiter... $delimiter = "================================\n"; local($/) = $delimiter; my $cnt=1; while(){ my $outfile = "> output_file_" . $cnt; open(OUT,$outfile)||die"Cannot open $outfile\n$!\n"; print OUT; close(OUT); $cnt++; }