Everybody has done great at telling you this much about this small query, I would just reiterate it in a different way by giving you the technical names and some aspects.

"^" is considered to be an assertion, it gives you more control, so here the "^" makes you match the beginning of the line, without it there, the program logic would go back and do another loop journey every time it encounters "\n" but you want to only capture those new-line characters that happen at the beginning , you got other assertions to match the end of the line or string or word boundary...etc, read about them,because regular expression is so important in Perl,without it you are in a fix

"\" in \n is an escape character, it helps to extend a meaning to an otherwise normal letter, like t and \t are not the same thing

the most important feature here in your question is the "and", this is sort of an if statement but in a different way, Marshall has given you useful tips on other ways to achieve the same thing, here I would just add to you that this special "and" is called "logical and" operator, it works as a short-circuit, that is, unless the left expression is true it would not proceed to evaluate the right expression or operand since operators work on operands mostly right?

so what happened here is that if the left expression is true, (a string beginning with a new line) the "and" would evaluate the right expression, next, next means repeat over the loop from the start again.
Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind

In reply to Re: About a piece of code by biohisham
in thread About a piece of code by trewq

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.