You are using the Switch module, which can cause weird situations due to its code rewriting nature.

As a first step, have you tried rewriting your code without use of the Switch module?

As a second step, remove parts of your code until the problem disappears. Most likely, the part you removed contains a part of the problem. You have posted far too much code and far too little input data for us to properly attempt to reproduce your problem. See SSCCE for what helps us help you better.

Note that you are using chomp:

chomp($line);

This will not remove any ^M characters from the end of $line.

Most likely, you want to remove all whitespace from the end of the line instead, or all "newline-ish characters":

$line =~ s![\r\n]+$!!; # just newlines $line =~ s!\s+$!!; # all kinds of whitespace

In reply to Re: Hidden Newline in Result by Corion
in thread Hidden Newline in Result by phamalda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.