package ShoppingCart; sub new { my $class = shift; my $self = {}; bless $self, $class; $self->initialize(@_); return $self; } sub initialize { my $self = shift; $self->{IO} = shift; } sub PrintAll { my $self = shift; while (my $item = $self->{IO}->GetNext()) { ... } } ... package ShoppingCart::IO::File; # this is NOT a subclass of ShoppingCart!!! sub new { ... } sub GetNext {} sub ResetCounter {} ... package ShoppingCart::IO::DBI; sub new { ... } sub GetNext {} sub ResetCounter {} ... package main; my $IO = new ShoppingCart::IO::DBI $server, $username, $password; my $Cart = new ShoppingCart $IO; ...