#! /usr/bin/perl/ use warnings; use strict; #file to open my $somefile = "/home/lord-ivan/Soures_Code/Perl/projects/Data/EJDATA.LOG"; open (my $fh, '<:encoding(UTF-8)', $somefile) or die "Could not open file '$somefile' $!"; print "$somefile open"; #Extract ranges of lines from a file while (<$fh>) { if (/TRANSACTION STARTED/ .. /TRANSACTION END/) { next if /TRANSACTION\s*(STARTED|END)/; print $_; } } my $ofh; my $outputfile = "/home/lord-ivan/Soures_Code/Perl/projects/EJ Transport/Queue/.txt"; BEGIN {$outputfile= "EJ"}; open ($fh, ">>${$outputfile}.txt", print $fh $_); close($outputfile); $outputfile++;