Класс-синглетон


# Counter.pm

package Counter;

my $singleton = undef;

sub new
{
    my( $class ) = @_;

    return $singleton if defined $singleton;

    my $self = 0;
    $singleton = bless $self, $class;

    return $singleton;
}

sub value
{
    my $self = shift;
    return $$self;
}

sub increment
{
    my $self = shift;
    return ++$$self;
}

1;

* Пример использования:

#!/usr/bin/perl

use Counter;

my $count1 = Counter->new();
my $count2 = Counter->new();

print "Они одинаковые!n" if $count1 eq $count2;