my $flag; my @new = grep { $flag = 1 if $_ == $first; $flag = 0 if $_ == $last; $flag } @old;