use Modern::Perl; while (){ print $_ unless /\bgroup\b/; } __DATA__ This line is OK This line should be skipped: 'group' Drop this group too But keep this grouped content