#!/usr/bin/perl -w use strict; open (SOURCE, '<', 'test.txt') || die "Can't open test.txt: $!"; my @source = ; close (SOURCE); my $size=0; foreach(@source){ $size++ while m{\b\w+\b}g; } print "wordcount: $size words\n";