use strict; my $id = 24601; sub foo { # .. lotsa code print "ID number is", $id, "\n"; # .. more code } sub bar { if ($id = 3) { # Oops-- I've accidentally set $id to 3 # do something subtle } } #### BEGIN { my $id = 24601; sub get_id { return $id; } sub set_id { my ($new_val) = @_; $id = $new_val; } } sub foo { # .. lotsa code print "ID number is ", get_id(), "\n"; # .. still more code }