$ perl -MIO::Handle -le 'open my $fh, "<", shift or die $!; print $fh->input_line_number while <$fh>' a_file_name 1 2 3 4 . . . $ perl -MIO::Handle -le 'open my $fh, "<", shift or die $!; print (\$fh)->input_line_number while <$fh>' a_filename REF(0x99d7cdc) Can't call method "input_line_number" without a package or object reference at -e line 1, <$fh> line 1. # $fh = do {local *FH}; #bad $ perl -MIO::Handle -le 'my $fh = do {local *FH}; open $fh, "<", shift or die $!; print (\$fh)->input_line_number while <$fh>' a_file_name GLOB(0x846ccdc) Can't call method "input_line_number" without a package or object reference at -e line 1, line 1.