my $x="global"; my $test=sub { my $x="pre"; alert($x); # pre my ($name,$val)=@_; eval('$'.$name."='".$val."'"); alert($x); # post }