in reply to how to deal with newline

-n reads the file line by line. Have you looked at what $_ contains for each of your checks?