sub how_many_lines { open I, 'users.dat' or warn("Couldn't open users.dat\n"), return; # That single statment will try to open "users.dat" # (it better be in the current directory). If that # fails, it'll print "Couldn't open users.dat" and # return undef (the undefined value) to the calling # routine. Yes, it's very terse, but that's part of # the power of Perl. my $lines; # Declare $lines local to this scope (the sub) ++$lines while ; # Read the entire file a line at a time, incrementing $lines # every time. close I; # Close the file handle $lines; # return the count to the caller. }