############# UNTESTED ################ use strict; my $pvid = ''; # initialize my @output = `command`; # Output looks like 7 lines and on [one] line is the pvid: # pvid 00c1be9a467335ce0000000000000000 # I use qx/command/; # easier to see in code for me! foreach my $line ( @output ) { # print "$line\n"; ## If not working, use print to figure out what's happening if ( substr( $line, 0, 5 ) eq 'pvid ' ) { $pvid = substr( $line, 6, 16 ) # or '32' as you require last; } } if ( $pvid eq '' ) { ... } ## Generate warning or do some error handling!