open (INPUT, $ARGV[0]) or die "I couldn't get at input text"; open (OUTPUT, '>outfile.txt') or die "Can't write to outfile: $!"; while ($line = ) { #chop ($line); if (( $line =~ /index_1/ ) and ($line =~ /6/)) { $i=0; while ($i<2) { $line = ; # gets next line $i++; } print OUTPUT $line;} }