Parsing email is not a trivial task. Maybe using a CPAN library might be safer. I can't recommend anything (haven't used one yet), but someone else might have an idea what to use. I found http://search.cpan.org/~markov/MailTools-2.07 with a quick search, check out the demos

What you want is a parser. For simple line oriented tasks a FSM (Finite State Machine) is often a good practical solution that keeps the complexity in check. In Re^3: How to parse a text file there is a simple example of a FSM. What you do with $lineBufferStatus is already a simple FSM. But you would need at least another state that says "I'm at the To-line now"

By the way to check if an array is empty, int() is rather unusual. Well TMTOWTDI, but the following lines are equivalent and the last of them is commonly used and as safe as your version

if (int(@array)>0) { if (scalar(@array)>0) { if (@array>0) { if (@array) {

In reply to Re: Help appending data based on location by jethro
in thread Help appending data based on location by perlnewbie9292

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.