in reply to Use variable outside if statement

You have to create $lookfor at a broader scope. The {...} brackets effectively limit the variable's scope. Here is how you would make it available outside of the {...} block:

use strict; my $lookfor; if ( $line =~ /TC/g ) { $lookfor = "TC"; } else { $lookfor = "26"; }

Update: Or you could use a different Perl idiom:

use strict; my $lookfor = ( $line =~ /TC/g ) ? "TC" : "26";

Note, in the snippet you provided, the /g modifier on your RE isn't doing anything for you.


Dave