in reply to Re: Get string for a word in a file after some specific pattern compare
in thread Get string for a word in a file after some specific pattern compare

$1 will not contain the word from the regex, because the special regex variables are automatically localized to the enclosing blocks. As perlre explains it:
$<digits> Contains the subpattern from the corresponding set of parentheses in the last pattern matched, not counting patterns matched in nested blocks that have been exited already. (Mnemonic: like \digits.) These variables are all read-only.
Since the while block has been exited, by the time you check $1 it contains the value it held before the while block was executed.

Try this instead:

my $value = 'not found'; while (<FILE>) { $value = $1, last if /TARGET\s?=\s?(\S*)\s/; }