Немного более чистая версия с более современным использованием perl (три параметра открываются с лексическими файловыми дескрипторами, проверка ошибок для вызовов open
)
#!/usr/bin/perl
use strict;
use warnings;
my $in_file = 'file_2b_read.txt';
my $out_file = 'newfile_2b_part_%06d.txt'; # Template for output filenames
my $counter = 1;
open my $in_fh , '<' , $in_file or die $!;
open my $out_fh , '>' , sprintf( $out_file , $counter ) or die $!;
while( <$in_fh> ) {
print $out_fh $_;
if( /^END/ ) {
close( $out_fh ) ;
open $out_fh , '>' , sprintf( $out_file , ++$counter ) or die $!;
}
}
# cleanup afterwards
close $out_fh ;
close $in_fh ;