use strict; my @foo; push @foo, Foo->new() for (0..4); package Foo; { my $count = 0; sub get_count { return $count } sub inc_count { return ++$count } } sub new { my $class = shift; $class->inc_count(); print STDERR 'there are ', $class->get_count(), " instances\n"; my $self = { bar => 42 }; return bless $self, $class; }