in reply to Count elements in array ref

Maybe I'm missing the point here, but is there some reason that you don't use the $#$ construct? You even have it in your comments.

#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; my $data = ['alpha', 'beta']; my $count = $#$data + 1; is ($count, 2, 'With elements'); $data = []; $count = $#$data + 1; is ($count, 0, 'Without elements'); $data = undef; $count = $#$data + 1; is ($count, 0, 'As undef');

By my reading of your post this seems to satisfy all your criteria and is both clear and concise. HTH.