use strict; my $cmd="netstat >>C:\\perl-program\\test2\\netstat_ouput.txt"; system($cmd); my $file_name="netstat_ouput.txt"; my $pattern='WXP-DPBG8BS\s*:\s*(\d?\d?\d?\d?\d?)'; open(FH,"$file_name") or die "Could not able to open the file !"; while(<FH>) { my $line=$_; #print "$_\n"; if ($line=~m/$pattern/) { print "$line\n"; my @list=split $pattern,$line; print "Match is found ->!\n"; our @array=split ':',@list; foreach my $port(@array) { print "Port found:$port\n"; #print "Test\n"; } } else { print "No Match\n"; } } <c> =========================== netstat_output.txt ===========================<c> Proto Local Address Foreign Address State TCP WXP-DPBG8BS:1054 localhost:5354 ESTABLISHED TCP WXP-DPBG8BS:1440 localhost:27015 ESTABLISHED TCP WXP-DPBG8BS:1447 localhost:1448 ESTABLISHED TCP WXP-DPBG8BS:1448 localhost:1447 ESTABLISHED TCP WXP-DPBG8BS:5354 localhost:1054 ESTABLISHED TCP WXP-DPBG8BS:27015 localhost:1440 ESTABLISHED
===================================== Need to have below output but output is not coming. Desired Output:- =====================================
port found:3743 port found:3744 port found:3745 port found:3746 ..............
===================================== Can you please help me to fix the code ?

In reply to Extract Port value from netstat file by saikat

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.