use strict; for $find = "END OF EXPANDED DATA"; open (NEW, ">", "FILE_OUTPUT.txt" ) or die "could not open:$!"; open (FILE, "<", "FILE.txt") or die "could not open:$!"; while () { if (/$find/){ print NEW "\n"; } } close (FILE); close (NEW);