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() { 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"; } } =========================== netstat_output.txt =========================== 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 #### port found:3743 port found:3744 port found:3745 port found:3746 ..............