in reply to Extract Port value from netstat file

You probably want something like this:

use warnings; use strict; my $cmd = 'netstat'; my $pattern = qr/WXP-DPBG8BS\s*:\s*(\d+)/; open my $PIPE, '-|', $cmd or die "Could not open the pipe from '$cmd' +because:$!"; while ( <$PIPE> ) { if ( /$pattern/ ) { print "port found: $1\n"; } } close $PIPE or warn $! ? "Error closing $cmd pipe: $!" : "Exit status $? from $cmd";