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