use File::Find; use IO::File; find(\&wanted, $jscriptdir); sub wanted { if (/\.js$/) { my $fh = new IO::File($_) or die("Can't open $File::Find::dir/$_"); while (<$fh>) { # your while here } $fh->close(); } }