$ cat scoping.pl #!/usr/bin/env perl use strict; use warnings; my $data = <<'EOD'; 72 EOD open my $fh, '<', \$data; while (my $line = <$fh>) { while ( $line =~ /.*st_mem_bit.*(\d+)/g ) { my $num= $1; } } print $num; close $fh; $ ./scoping.pl Global symbol "$num" requires explicit package name at ./scoping.pl line 22. Execution of ./scoping.pl aborted due to compilation errors. $