If you read the contents of your config.txt file into a variable, you can use a regex containing "Link encap:" to capture the IPs:

use Modern::Perl; my $data = do { local $/; <DATA> }; my ( $eth0, $lo ) = $data =~ /Link encap:.+inet addr:([\d.]+).+inet addr:([\d.]+)/s; say $eth0 ? "eth0 => $eth0\nlo => $lo" : 'not ethernet'; __DATA__ eth0 Link encap:Ethernet HWaddr 00:0C:29:0F:9B:82 inet addr:192.168.8.76 Bcast:192.168.8.255 Mask:255.255.25 +5.0 inet6 addr: fe80::20c:29ff:fe0f:9b82/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:280252 errors:0 dropped:0 overruns:0 frame:0 TX packets:106184 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:35501675 (33.8 MiB) TX bytes:11696548 (11.1 MiB) Base address:0x1080 Memory:f4820000-f4840000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:4664 errors:0 dropped:0 overruns:0 frame:0 TX packets:4664 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7952486 (7.5 MiB) TX bytes:7952486 (7.5 MiB)

Output:

eth0 => 192.168.8.76 lo => 127.0.0.1

"not ethernet" will be printed if "Link encap:" is not in the config.txt contents.

Hope this helps!


In reply to Re: how to check condition and then pattern match by Kenosis
in thread how to check condition and then pattern match by laksh

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.