my @a = (1, undef, 3); # Now scalar @a = 3, but there are only two elements of interest. # Brute force counting method: my $c = 0; $c++ for (grep { defined } @a); # $c now holds the number of defined elements, in this case 2.