in reply to Counting in regular expressions
but, I think, what you really want is 'split':use strict; use warnings; my $count; # get $input from some place $input =~ s/^\s+//; # dump leading whitespace while ($input =~ s/[^\s]+\s+//) { ++$count; } ++$count if ($input =~ /./); # catch the last word
my @array = split /\s+/, $input; $count = scalar (@array);
|
|---|