my @new = (1,2,3,4); my @old = (4,5,6,7,8); my $num_elements = 3; push @new, grep { !($_ ~~ \@new) && $num_elements-- > 0 } @old;