It does not work if the array ref returns nothings my $data = data(); my $count = scalar(@$data); # $#$data; print $count;