#!/usr/bin/perl use strict; use warnings; use autodie; sub usage { my $err = shift and select STDERR; print "usage: extract.pl firstline lastline filename\n"; exit $err; } # usage use Getopt::Long qw(:config bundling nopermute); GetOptions ( "help|?" => sub { usage (0); }, ) or usage (1); my ($start, $stop, $file) = @ARGV; -s $file && $start =~ m/^[0-9]+$/ && $stop =~ m/^[0-9]+$/ && $start <= $stop or usage (1); open my $fh, "<", $file; while (<$fh>) { $. >= $start && $. <= $stop and print "$.: $_"; } close $fh;