#!/usr/bin/env perl use strict; use warnings; use autodie; my $file = 'pm_1139175_skip_head_and_foot.txt'; my ($headers, $footers) = (2, 3); open my $fh, '<', $file; <$fh> for 1 .. $headers; my $last_head_pos = tell $fh; 1 while <$fh>; my $last_data_line = $. - $footers; seek $fh, $last_head_pos, 0; $. = $headers; while (<$fh>) { last if $. > $last_data_line; print; } close $fh;