#!/usr/bin/perl -w use strict; my $dir = 'C:\Users\ZB\Desktop\Text Files'; opendir (DIR, $dir) or die "cannot opendir $dir"; foreach my $file (readdir(DIR)) { next if $file eq '.'; next if $file eq '..'; process_file ($file); } sub process_file { my $fname=join("/",@_); open FIN,"< $fname" or die "$fname:$!"; my @lines=; chomp @lines; close FIN; my $count=0; foreach my $line(@lines) { map { $count++ } split (/[\s\t\n]+/,$line); } printf "There are %d words in %s\n",$count,$fname; } closedir (DIR);