my $input = ; chomp $input; my $script_name = ''; #This is in the main scope if ($input =~ /runme(.+)$/) { $script_name = $1; #$1 is in the scope of #the 'if' block } if ($script_name) { print "Running $script_name\n"; } else { print "Running $input\n"; }