package Product; use Tie::Array; @ISA = qw/Tie::StdArray/; use strict; sub TIEARRAY { my $class = shift; bless [ @_ ], $class; } sub FETCH { my $them = shift; my $index = shift; return $index >= @$them ? eval join '*', @$them : $them->[$index]; } package main; ## Initialize your array with 2 elements, 8 and 2 tie my @p, 'Product', 8, 2; print $p[2], "\n"; ## Change the second element to 5 $p[1] = 5; print $p[2], "\n"; ## You can even add new elements to the array; now ## you need to use $p[3] to get the product push @p, 10; print $p[3], "\n";