while (<>) { next if /line to skip/; print unless ($startline .. $endline) or (/skip start line/ .. /skip end line); }