in reply to Re^2: Differentiating STDIN from arguments when using -n ?
in thread Differentiating STDIN from arguments when using -n ?

Don't declare the $x — it's just a one-liner. Perl wraps a while(<>) { ... } loop around the code you put there (really!), so it's a new $x for every line in the file.

See for yourself:

perl -n -MO=Deparse -e 'my $x' foo
produces:
LINE: while (defined($_ = <ARGV>)) { my $x; } -e syntax OK