#! /usr/bin/perl use warnings; use strict; # Skip 6 lines at beginning of file # Throw away 3 lines before \f # Skip 5 lines after \f use constant LINES_TO_SKIP_AT_START => 6; use constant LINES_TO_SKIP_BEFORE_FF => 4; use constant LINES_TO_SKIP_AFTER_FF => 3; our @lines; our $lines_to_skip = 6; LINE: while ( <> ) { if ( $lines_to_skip ) { --$lines_to_skip; next LINE; } if ( /\f/ ) { $#lines -= LINES_TO_SKIP_BEFORE_FF; $lines_to_skip = LINES_TO_SKIP_AFTER_FF; next; } push @lines, $_; print shift @lines if @lines > LINES_TO_SKIP_BEFORE_FF; } # Get rid of the last few lines if they are blank: for ( my $i = $#lines; $i >= 0; --$i) { last if $lines[ $i ] =~ /\S/; --$#lines; } print @lines;