sub log_it { state $fh = do { open my $x, '>>', 'mylog.txt'; $x }; my $message = shift; my $timestamp = time; print $fh $timestamp . ": " . $message . "\n"; }