use strict; my $n="0000"; while (<>) { if (/^<\?xml version/) { open OF, ">outfile_$n.xml" or die "open: $!\n"; $n++; } print OF $_; }