... my $counter; $counter++ while $string =~ /\w+/g; print "Word count: $counter\n"; ...