The first major problem with your code is that the regular expression you use in the split is wrapped in single quotes so the match you are using is not at all the match you expect! The next issue is that you seem to want to deal with a number of lines that have been split into an array, but the array is in scalar context in the split so you get the count of elements as the string to be split instead of each line. But even fixing that won't do what you want. As a starting point consider the following code:

#!/usr/bin/perl use warnings; use strict; my $str = <<TICKSTR; Pinging 127.0.0.1 with 32 bytes of data: Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Reply from 127.0.0.1: bytes=32 time<1ms TTL=64 Ping statistics for 127.0.0.1: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms TICKSTR for my $line (split /\n/, $str) { next if $line !~ /^Reply/; my @parts = split / /, $line; print "$_\n" for @parts[4, 5]; }

Prints:

time<1ms TTL=64 time<1ms TTL=64 time<1ms TTL=64 time<1ms TTL=64

$str contains the result you might get using my $str = `ping 127.0.0.1`. The first split extracts the lines and the for loop loops over them. We are only interested in the "Reply" lines so we skip everything else. The second split breaks reply lines up into parts and the final statement prints out the two parts of the line of interest.

True laziness is hard work

In reply to Re: Unable to extract elements from a split. Kindly Help. by GrandFather
in thread Unable to extract elements from a split. Kindly Help. by perl514

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.