#! perl -slw use strict; package paw; sub new { my $class = shift; return bless { @_ }, $class; } sub scratch { my $self = shift; print "Scratching with $self->{ which } paw"; } package cat; sub new { my $class = shift; my %self = @_; $self{ paws } = { map{ $_ => paw->new( which => $_ ) } 'left front', 'right front', 'left hind', 'right hind' }; return bless \%self, $class; } sub scratchesWith{ my( $self, $paw ) = @_; $self->{ paws }{$paw}->scratch(); } sub speaks { my $self = shift; print $self->{name}, ' says: ', $self->{voice}; } 1; package main; my $cat = cat->new( name => 'Tiddles', voice=> 'Meow!', ); $cat->scratchesWith( 'right front' ); $cat->speaks(); __END__ [ 4:08:26.92] P:\test>405381 Scratching with right front paw Tiddles says: Meow!