use strict; use warnings; use feature 'say'; use Tie::File; my $input_file = shift; my $output_file1 = shift; my $output_file2 = shift; my @lines; tie @lines, 'Tie::File', $input_file or die "Unable to open file '$input_file': $!"; my $index = 0; open(my $fh1,">",$output_file1) or die "Unable to open file '$output_file1': $!"; open(my $fh2,">",$output_file1) or die "Unable to open file '$output_file1': $!"; while ($index <= $#lines) { next if (); #insert logic to determine which lines are ignored my $current_line = $lines[$index]; my $fh; if () { #insert logic to determine that current line goes to first file $fh = $fh1; } else { #assumes if not skipped and not for first file, goes to 2nd file $fh = $fh2; } say $fh $lines[$index]; #if needed, modify next if statement to determine if current line requires #copying the next 4 input file lines if ($lines[$index] =~ m/SDP_CMD_WRSIZEDFULL/i) { say $fh $lines[$index + 1]; say $fh $lines[$index + 2]; say $fh $lines[$index + 3]; say $fh $lines[$index + 4]; $index += 5; next; } $index++; } untie @lines; close($fh1); close($fh2);