http://qs1969.pair.com?node_id=547106


in reply to Counting the number of items returned by split without using a named array

Why not just count the instances of whitespace?
my $str = "this is a test string"; my $cnt = 1; # num tokens = whitespace + 1 ++$cnt while $str =~ /\s+/g; print $cnt, "\n"; # prints 5