my @hold; for (@array) { if (my $status = /^\*{3}1\*{3}$/../^\*{3}end1\*{3}$/) { next if $status == 1 or $status =~ /E0/; push @hold, $_; } }