open(FILE, "< $file") or die "can't open $file: $!"; $count++ while ; # $count now holds the number of lines read open(FILE, "< $file") or die "can't open $file: $!"; for ($i=0; ; $i++) { if ($i == $count) { # Validate last line } }