#!/usr/bin/perl use warnings; use strict; while () { my $remove_new_line = /string1/ .. /string2/; chomp if $remove_new_line and 0 > index $remove_new_line, 'E'; # not the last line print; } __DATA__ x y z string1 a b c string2 1 2 3 #### x y z string1abcstring2 1 2 3