my @a = grep { condition($_) } @b; # same as my @a; for (@b) { push @b, $_ if condition($_); } @a