perl -wn000e # -n read file, 000 set $/ (input separator) to nil # hence, read whole file into $_ '$start = 1034; # number of the line to start printing at $end = 1047; # number of the line to end printing at $pre = $start - 1; # the number of lines to skip before printing $len = $end - $start + 1; # the number of lines to print print / (?: # don't remember this () in $1..$n .*\n # all chars up to a newline and the \n ){$pre} # pre number of times ( # remember this (return it as first el of list) (?: # but don't remember this part as 2nd element .*\n # match a line up to and including \n ){$len} # number-of-lines-to-print times ) # return as single (multi-line) value /mx' # /m: don't let '.' match \n (may not be necessary)