in reply to Split file

Assuming that your data file always begins with a matching pattern on the first line as in the sample data you provided, the following would work.

use strict; use warnings; while(<DATA>){ if(/DN:$/){ chomp(my $filename = <DATA>); open FH, '>', $filename or die; } else { print FH $_; } }