>does $#foo start with an unquoted # character?
Er, well, no, but if the rule is "any time an unquoted # appears in a line of Perl, then the remainder of the line is ignored" then the rule is not correct in respect of that line, is it?
Obviously there are special cases where that rule is qualified with an "unless blah blah blah" clause.
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.
That's not the rule. Of course, the best way to know the
rule is to read the source, but the summary of the rule
you quoted originally is adequate to explain the behavior you describe. (and your later summary is very different in practice).
Here's another rephrasing:
If you're not inside quotes of some kind, a hash symbol that
isn't inside another token starts a comment.