#!/usr/bin/perl use strict; use warnings; my ( $sp, $port ) = qw( A 5 ); # perldoc perlretut; perldoc perlrequick; perldoc perlre my $regex = qr{ SP\sName:\sSP\s\Q$sp\E \s+ SP\sPort\sID:\s\Q$port\E \s+ .* Link\sStatus:\s(\S+) \s+ }sx; { # perldoc perlvar local $/ = "\n\n"; while ( my $block = ) { if ( $block =~ $regex ) { print "Link Status: $1\n"; } } } __DATA__ SP Name: SP A SP Port ID: 4 SP UID: 50:06:01:60:C1:E0:2B:7A:50:06:01:60:41:E0:2B:7A Link Status: Up Port Status: Online Switch Present: YES Switch UID: 10:00:00:05:1E:03:D9:16:20:07:00:05:1E:03:D9:16 SP Source ID: 67328 MAC Address: Not Applicable SFP State: Online Reads: 3064353 Writes: 17936913 Blocks Read: 103971645 Blocks Written: 867380028 Queue Full/Busy: 0 SP Name: SP A SP Port ID: 5 SP UID: 50:06:01:60:C1:E0:2B:7A:50:06:01:61:41:E0:2B:7A Link Status: Down Port Status: Online Switch Present: NO MAC Address: Not Applicable SFP State: Online Reads: 0 Writes: 74801 Blocks Read: 0 Blocks Written: 19186170 Queue Full/Busy: 0