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