Terry said:
Thanks for the response! Can you point a few example scripts on how
this is done? I am new to programming and new to perl too.
You sound like you need the number to be persistent across different
executions of the script?
People commonly use modules like Data:

umper (spelling and correct choice
not tested ;-) to export values, or just write it to a file and re-read
it. Most solutions are quite straight-forward and similar to any solution
you might make in any language.
I made a simple module that implements a persistent value in a little text
file. Efficiency is not great but it's workable for low volumes of
activity. I don't think the module is sufficiently interesting to submit
to CPAN, but here's the module file Persist.pm:
use strict;
use warnings;
package Persist;
use Fcntl;
use Carp;
sub TIESCALAR {
my $class = shift;
my $filename = shift;
my $self = { };
local *FD;
sysopen FD, $filename, O_RDWR | O_CREAT | O_SYNC
or croak "cannot open $filename: $!";
$self->{fd} = *FD{IO};
my $value = <FD>;
chomp $value if defined $value;
$self->{value} = $value;
bless $self, $class;
} # TIESCALAR
sub STORE {
my $self = shift;
my $value = shift;
$self->{value} = $value;
local *FD = $self->{fd};
seek FD, 0, 0;
print FD "$value\n";
truncate FD, tell FD;
return $value;
} # STORE
sub FETCH {
return $_[0]->{value};
} # FETCH
1;
__END__
This module (when I show you how to use it) will keep your variable stored
in a file, but it will not be 100% reliable if multiple instances of the
same script will use it in parallel. If your problem includes many scripts
running simultaneously you need an entirely different and more robust
solution. Do not trust my solution to keep your numbers unique in that
case!
You need to put this module file in a suitable place. If you maintain a
private library directory and know how to point to it, that's the go. Or
you can store it in the same directory as the script and access it in a
flexible way that doesn't demand hard-coded paths in your script. But
comfortably accessing this module is really another question with a few
possible answers that you might already know...
To use the module:
....... STUFF TO LOCATE THE MODULE ....
use Persist;
.....
my $serial = 0;
my $filename = "integer.txt";
tie $serial, 'Persist', $filename;
Now you may treat $serial as an ordinary variable and whenever you assign
to it, it will be re-written to the file. Clearly not very efficient for
huge number of allocations in rapid succession.....
eg
my $nextnum = ++$serial;
and away you go. When the script terminates the file will be closed
automatically perl.