Another option is to regex your file's slurped contents:

use Modern::Perl; my $fileContents = <<END; 0.0.0.0/0 *[Static/5] 02:30:27 > to 192.168.4.126 via em0.0 10.0.0.36/30 *[OSPF/10] 01:46:15, metric 2 > to 10.0.0.106 via em1.0 [BGP/170] 01:43:15, localpref 100, from 10.0.0.131 AS path: I 10.0.0.128/32 *[Static/5] 02:22:14 > to 10.0.0.110 via em2.0 [OSPF/10] 01:46:15, metric 3 > to 10.0.0.106 via em1.0 END { local $/; open my $fh, '<', \$fileContents or die $!; my $data = <$fh>; my @IPs = $data =~ /Static.+Static.+> to ([\d.]+) via.+> to ([\d.] ++) via/s; say for @IPs; }

Output:

10.0.0.110 10.0.0.106

In reply to Re: Finding specific keyword in Perl by Kenosis
in thread Finding specific keyword in Perl by zakishah

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.