use warnings; use strict; #Note that this script throws errors when pull file paths are defined. #Must be run from the path that the input/output files exist. open my $fhi, '<', 'cr835.txt' or die "$!"; open my $fho, '>', 'cr_output.txt' or die "$!"; #Prints the first 14 lines to the output file while(<>) { 1 .. 14 ? print : last; } #Prints content starting with LX* and ending with CAS* #but only if 00003 exists { local $/ = 'CAS*'; while (<$fhi>){ print $fho if /LX\*.*(?=00003$)/s; } } #Prints the last 3 lines of the file while () { $. < $lines - 3 and print while } close $fhi; close $fho;