use 5.012; package ArraySlice; use base qw(Tie::Array); sub new { my ($Self, $base, $offset, $length) = @_; bless { base => $base, offset => $offset, length => $length }, $Self; } sub newref { my ($Self, @args) = @_; tie my @slice, $Self, @args; return \@slice; } sub TIEARRAY { my ($Self, @args) = @_; return $Self->new(@args); } sub EXISTS { my ($self, $index) = @_; return 0 <= $index && $index < $self->{length}; } sub FETCH { my ($self, $index) = @_; if ($self->EXISTS($index)) { return $self->{base}->[$self->{offset} + $index]; } else { return undef; } } sub FETCHSIZE { my ($self) = @_; return $self->{length}; } package main; my @foo = qw(oans zwoa dreie fiare finwe); my $slice = ArraySlice->newref(\@foo, 1, 3); say foreach @$slice;