my $i = 0; while ($i < @r) { if (r($r[$i]) { push @l, (splice @r, $i, 1); next; } $i++; }