http://www.perlmonks.org?node_id=1199681


in reply to Splitting a file based on matched conditions

#!/usr/bin/perl # http://perlmonks.org/?node_id=1199646 use strict; use warnings; use Path::Tiny; local $/ = "\nEnd"; while(<DATA>) # read section to (and including) End { $_ .= do { local $/ = "\n"; <DATA> }; # complete last line /\nEnd (\d+).*$/ and path("OUTFILE$1")->append($_); } __DATA__ Start:/abc/def ..... End 1.2 Start:/xyz/uvw ..... End 2.8