This may be what you want now, but really you need to sort out what problem you actually need to solve.

Note that this is still reading the data a line at a time rather than slurping the data as your code was. Unless this code is part of something larger that needs to further process the original data there is no advantage in slurping everything. Even if you did need to process the data further, you would be better to slurp into an array than to slurp the whole thing into a scalar.

use strict; use warnings; my $dumpIPs = 0; while (<DATA>) { if ($dumpIPs and /((\d{1,3}\.){3}\d{1,3})/) { print "$1 "; } elsif ($dumpIPs) { print "\n\n"; $dumpIPs = 0; } if (/\b(?:Device|interface|VRID|state|primary address)\b/i) { print; $dumpIPs = 0; } $dumpIPs ||= /Number addresses/; }
__DATA__ logging to Device F01 is 19.9.16.11... Showing the vrrp status VRRP Interfaces Interface WEB_A Authentication: NoAuthentication VRID 39 State: Master Time since transition: 582693 hfghfghfghghghfghfhhfgh Primary address: 195.51.205.220 Number addresses: 1 195.51.205.222 Monitored circuits: Afgh_A (priority 1fgh50) SRghf1 (priority 1fgh50) Interface DATA_DL Nufghfghmber of vhfghl roufgh Fgfhfghs: AuthefghfgntichoAhfhication VRID 2556 State: Master Time since transition: 13405375 Bahfgh Flafghfghgs: Advertfghdl: 1 Rfghfghfgval: 3fghfghfgh fghfsgh VfghfghVRghfg Vh Primary address: 19.18.27.65 Next advertisement: 0 Number addresses: 1 15.12.57.234 I logging to Device L2 is 14.359.1.2... Showing the vrrp status VRRP Interfaces Interface SDC_A Nughujgj AuthentijghjghjNoAuthentication VRID 9 State: Backup Time since transition: 582695 Mghjghjer: hgjghjghj0 BahhjFlags: Adverghjad Interval: 3 VMAChj VMAhj1:ef Primary address: 195.51.205.221 Masghjghjg Number addresses: 1 195.51.205.222 Interface SA Numbehgjghjr of virtualj: 1 Fghjg Authentijghjtion VRID 7 State: Backup Time since transition: 582695 Master: 62.187.224.12 Baseghjghj4 Flags: Advertisement ihjghjRouterhjghj3jghjVRRP VMAC: ghj:01jghj Primary address: 62.187.224.13 Mastghjghj Number addresses: 1 6.17.26.14

Prints:

logging to Device F01 is 19.9.16.11... Interface WEB_A VRID 39 State: Master Time since transition: Primary address: 195.51.205.220 195.51.205.222 Interface DATA_DL VRID 2556 State: Master Time since transition: Primary address: 19.18.27.65 15.12.57.234 logging to Device L2 is 14.359.1.2... Interface SDC_A VRID 9 State: Backup Time since transition: Primary address: 195.51.205.221 195.51.205.222 Interface SA VRID 7 State: Backup Time since transition: Primary address: 62.187.224.13 6.17.26.14

DWIM is Perl's answer to Gödel

In reply to Re^5: just another search program by GrandFather
in thread just another search program by sunny

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.