#!/usr/bin/perl use strict; use warnings; my ($start, $stop) = (qr '#ifdef|#if defined', qr '#endif'); open INPUT, '<', 'monks23.dat' or die "Error opening input: " . $!; while () { if (/$start/ .. /$stop/) { # Print the lines themselves if (/$start/ or /$stop/) { print; } # Skip the rest next; } print; } close INPUT;