#!/usr/bin/perl use strict; use warnings; my $COUNT = 0; while(){ $COUNT++ while m{\b\w+\b}g; } die "COUNT $COUNT"; __END__ Hello there boss! How are you doing today. I really hope you don't slip on that banana peel. I count 22 words.