$_ = ' this is a string'; my @words = split " "; print scalar @words, "\n"; # or you could go for this version :-) $_ = ' this is a string'; my $words =()= /(\S+)/g; print $words, "\n";