/me is with hbm on "INTERFACENAME." The logic of the question, it seems to me, requires that "INTERFACENAME" be OP's standin for variable text. And on that interpretation, bart's answer is elegant after one coerces the data into a single string. ++

So, TIMTOWTDI. I've assumed variable text (and that the variable text ends with an uppercase alpha, [A-Z] character).

#!/usr/bin/perl use Modern::Perl; # 938143 my $cachedline=""; my $multiline=""; my (@data, $line, @array_of_routeinfo); my $re = qr/directly connected, /; while ( <DATA> ) { # slurp __DATA__ push @data,$_ ; } for $line(@data) { chomp $line; $line =~ s/ $//g; # clean up data; one of mine had trailing s +paces if ($line eq '') { say "No more data"; exit(1); } if ( ($line =~ /$re/ && $cachedline eq "") ) { push @array_of_routeinfo, $line; } elsif ( ($line !~ /$re/) && ($line =~ /\d$/) ) { # if $line do +esn't contain "directly connected, " and ends with number $cachedline= $line; } elsif ( ($line !~ /re/ && $cachedline ne "") ) { # no "directly + connected, " AND $cachedline has content $multiline = "\t $cachedline"; $multiline .= "\n\t $line"; push @array_of_routeinfo, $multiline; $cachedline = ""; } } for (@array_of_routeinfo) { say; } say "Done"; __DATA__ C AAA.BBB.CCC.DDD 255.255.255.224 is directly connected, FOO O E1 WWW.XXX.YYY.ZZZ 255.255.224.0 [110/112] via AAA.BBB.DDD.EEE, 696:56:46, BAR B 111.222.333.444 255.255.255.0 [914/212] via 111.222.333.444, 345:59:03, BAZ X EEE.FFF.GGG.HHH 255.255.255.123 is directly connected, BAT 3 L1 OOO.PPP.QQQ.RRR 255.255.111.77 [A10/304/0xDFEE] via 444.333.222.000, 504:27:88, BLIVITZ

Output is:

C AAA.BBB.CCC.DDD 255.255.255.224 is directly connected, FOO O E1 WWW.XXX.YYY.ZZZ 255.255.224.0 [110/112] via AAA.BBB.DDD.EEE, 696:56:46, BAR B 111.222.333.444 255.255.255.0 [914/212] via 111.222.333.444, 345:59:03, BAZ X EEE.FFF.GGG.HHH 255.255.255.123 is directly connected, BAT 3 L1 OOO.PPP.QQQ.RRR 255.255.111.77 [A10/304/0xDFEE] via 444.333.222.000, 504:27:88, BLIVITZ Done

In reply to Re: Trying to split a file into array conditionally by ww
in thread Trying to split a file into array conditionally by bobg2011

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.