It prints 1 for me, as I expected. If you run the program below and it prints 1 for you as well, something you said is not true. Find out what, and you'll find your problem.

$dev_ref->{hostname} = '2383-RWAN-1'; $dev_ref->{grbr } = '2383'; my $pattern = qr{HOSTNAME:\s*(?:\d{4}-)?$dev_ref->{hostname}\s+GRBR:\s +*$dev_ref->{grbr}}i; my $buffer = <<'__EOI__'; 9600/ARQ Some Company ---> Unauthorized use of this router is prohibited <--- ******************************************************* * Hostname: 2383-rwan-1 GRBR: 2383 * * Model: Cisco 1234 * * Location: Ansalon , DL * ******************************************************* ---> Unauthorized Access is strictly prohibited <--- User Access Verification Username: __EOI__ my $hostname = $buffer =~ m/$pattern/i ? 1 : 0 ; print($hostname, "\n");

By the way, the i option on m/$pattern/i is useless, since it's already on for $pattern. Also, you should probably escape what you putt in from $dev_ref:
qr{HOSTNAME:\s*(?:\d{4}-)?\Q$dev_ref->{hostname}\E\s+GRBR:\s*\Q$dev_ref->{grbr}\E}i
Neither change would affect the result here, though.


In reply to Re: RegEx Confusion by ikegami
in thread RegEx Confusion by Argel

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.