in reply to Bad line numbers .. bad!

Your 1st code snippet prints 5 for me, as expected. I tried it on 2 versions of perl:
This is perl 5, version 12, subversion 2 (v5.12.2) built for x86_64-li +nux This is perl 5, version 14, subversion 2 (v5.14.2) built for x86_64-li +nux-thread-multi

Check for unexpected line endings? cat -A