use warnings; use strict; package Device; { sub new { my $self = bless {}, shift; $self->{s1} = Sensor->new; $self->{s2} = Sensor->new; $self->{s3} = "string"; return $self; } sub event { my ($self) = @_; for (keys %{ $self }){ if (UNIVERSAL::can($self->{$_}, 'motion')){ print "yep, '$_' is a sensor object\n"; } else { print "'$_' isn't a damned sensor!\n"; } } } } package Sensor; { sub new { return bless {}, shift; } sub motion { ... } } package main; my $device = Device->new; $device->event; #### yep, 's1' is a sensor object 's3' isn't a damned sensor! yep, 's2' is a sensor object