in reply to Re^3: Can't use undefined variable as a symbol reference
in thread Can't use undefined variable as a symbol reference

plus you can let perl do the counting. See perldoc perlvar, search for "$." or "input_line_number".