in reply to Use variable outside if statement

How do I get the variable $lookfor to be available outside the if statement?
In the spirit of answering the question and not questioning it, and only because others have already said what should be said, see Rebinding closures by scope and do:
use strict; use ScopeSaver; my $scopeobj; my $line = "A TC B"; if ($line =~ /TC/g) { my $lookfor = "TC"; $scopeobj = eval ScopeSaver->new(lexical=>['$lookfor']); } else { my $lookfor = "26 "; $scopeobj = eval ScopeSaver->new(lexical=>['$lookfor']); } $scopeobj->scope_eval('print $lookfor');