use strict; package Demo; my @handles; sub new { my $thingy=shift; my $args=shift; my $id=$args->{'id'}; # Note that $args->{'id'} is autovivified here, but # this is no problem as we're testing for definedness # further on my $class=ref($thingy)||$thingy; unless (defined $id) {$id=scalar @handles}; my $self=bless $id, $class; $handle[$self]={string => $args->{'string'}}; return $self; }