From $/ in perlvar:

Remember: the value of $/ is a string, not a regex.

The difference between your two 'assignment' statements is that the first one is actually an assignment (Assignment Operators) and the second is a logical test (Equality Operators). The result of the first is assigning $/ the result of a (probably) failed regular expression, which is "". The second is a test in void context, and thus does not change the value of $/ - it remains "\n". In short, it doesn't work that way and using warnings would have told you as much.

Given that you've already constructed a regular expression, your easiest/fastest solution would be to slurp the files and use the regular expression in a while loop:

#!/usr/bin/perl use strict; use warnings; local $/; $_ = <DATA>; while (m/(.+?(?:$|(?=\d{4}\-\d{2}\-\d{2}\s+\d{1,2}\:\d{1,2}\:\d{1,2})) +)/gs) { print "START${1}END\n"; } __DATA__ 2010-03-11 18:26:42,431 DEBUG 5 System 172.22.2.120 (null) asdfasd fas +fdsdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf asd fasd fasdf asdf asdf asdf as dfasdf 2010-03-11 18:26:42,431 DEBUG 9 System 172.22.2.120 (null)asdf asdf as +df asdf asdf asdf asdf asd fasdfaf as fasdf asdf asdf as df asdf asdf adsf sdf asdf a fasdf asdf asdfdf af 2010-03-11 18:26:42,431 DEBUG 8 System 172.22.2.120 (null)asdf asdf as +df asdf asdf asdf asfasdfasf asf asdf asdf asdf asd fasdf asdf asdf asdf asdf asdfasf asdf asdf

In reply to Re: PERL $/variable by kennethk
in thread PERL $/variable by Anonymous Monk

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.