while($input =~ m/(\w+)/g) { if( $input =~ m/[\w\s]/g) { $count++; } }