use strict; use warnings; package Foo::Bar; sub new { tie my @arr, 'Foo::Bar'; return bless \@arr, 'Foo::Bar'; } sub lalala { my $self = shift; print "Lalala\n"; } sub TIEARRAY { return bless [], 'Foo::Bar'; } sub FETCH { print "Fetch\n"; my ($self, $index) = @_; return $self->[$index]; } sub STORE { print "Store\n"; my ($self, $index, $value) = @_; return $self->[$index] = $value; } package main; my $a = Foo::Bar->new(); $a->lalala(); $a->[0] = 1; print $a->[0];