# (no need to change how $buff is assigned) # option 1: my ( $result ) = grep( /28/, split( /\n/, $buff )); my $target = ( split( / /, $result )[1]; # get 2nd token from matched line # option 2: my ( $target ) = ( $buff =~ /(\S+)\s+28\n/ );