#!/usr/bin/perl open(FILE1, $ARGV[0]) || die "Error: $!\n"; @lines = ; while ($line=){ if ($line=~/^BEGIN_TAG/){ ; #get next line if ($line=~/^X1/ .. /^X2/){ # get all between X1 and X2 print $line; # print all of it } } }