while (<>) { if (my $stat = /^group:/../^data:/) { print unless /^\s*$/ or $stat == 1 or $stat =~ /E/; } }