And just for completeness there is Simon Cozen's Attribute::Persistent which allows for the persistence of variables with the greatest of ease. Here's some example code from the docs
use Attribute::Persistent;
my %hash :persistent;
# Value retained between calls to the program.
$hash{counter}++;
# Explicitly provide a filename.
my %hash2 :persistent(SessionTable);