#!/usr/bin/perl package StaticCtr; sub new { my $this = shift; my $class = ref($this) || $this; my $self = {}; bless($self, $class); $self->{ctr} = 0; return $self; } sub inc { my $self = shift; $self->{ctr}++; return $self->{ctr}; } package main; my $c = new StaticCtr; for (1..6) { print " incremented to: " . $c->inc . "\n"; } print "Final value is " . $c->{ctr} . "\n"; #### [mattr@taygeta perlmonks]$ ./ctr.pl incremented to: 1 incremented to: 2 incremented to: 3 incremented to: 4 incremented to: 5 incremented to: 6 Final value is 6