#!/usr/bin/perl -w use strict; foo(4); foo(); { my $bar; sub foo { $bar = shift unless defined $bar; print "$bar\n"; } } __END__ #### #!/usr/bin/perl -w use strict; print scalar localtime(),"\n"; slow_once(5); slow_once(); { my $expensive_thingy; sub slow_once { unless (defined $expensive_thingy) { # make expensive thingy: sleep 5; $expensive_thingy = shift; } print scalar localtime()," :$expensive_thingy:\n"; } } __END__ OUTPUT: Sat Nov 3 15:55:31 2001 Sat Nov 3 15:55:36 2001 :5: Sat Nov 3 15:55:36 2001 :5: