## set stricture checking for the rest of the file scope use strict; ## see. man perllexwarn for why this is double-plus good use warnings; ## ah, heaven-sent use File::Find::Rule; ## for lexically scoped file-handles use IO::File; ## prevent subroutines from being able access program level variables { ## naked block's lexical scope my @files = File::Find::Rule->file() ->name("*.{pl,pm}") ->in( shift @ARGV ); ## $fl is in the foreach lexical scope foreach my $fl (@files) { ## ditto with $lc my $lc = count_lines($fl); print "$fl: $lc line".($lc != 1 && 's')." of code\n"; } } sub count_lines { ## will be closed when we exit the current scope my $fh = IO::File->new(shift) or die("ack: $!"); ## scoped (and therefore private) to count_lines() my $count = 0; $count++ while <$fh>; return $count; }