my $oldcontents; # initialize $oldcontents my $newcontents; sub my_test { # read from $oldcontents # write to $newcontents } my_test();