#!/usr/bin/perl use strict; use warnings; use 5.012; BEGIN: recover_var(); # main here # ... insert your existing code for getting the value here # Since you didn't tell us the variable name, we'll use $var and assume you've used it my $var; say "(\t\t Simulating execution of existing..."; say "\t\t code to obtain a (new) value for \$var"; say "\t\t and NOW simulating that said execution is complete. \t)\n"; $var += int(rand(113)); say "\n\tTake a pencil and write the current value of \$var, $var, on your yellow sticky."; say "\t Otherwise, the value of \$var will disappear when the RAM used by \n\t this script is returned to the OS on termination of the script./n"; say "\n\t\t\tTerminating..."; exit; sub recover_var { if ( !$var ) { print "\n\t Find your yellow sticky (you did write down the old value, didn't you?) \n\t and enter the last \$var found on the sheet\n\t or '0' if no sticky is found: "; chomp ($var = <>); say "\n The last known value of \$var was $var.\n"; return; } }