use strict; use warnings; use feature qw{ say }; # =========== package Incrementor; # =========== use Tie::Scalar; our @ISA = qw{ Tie::StdScalar }; sub TIESCALAR { my( $pkg, $value ) = @_; $value //= 0; return bless \ $value, $pkg } sub FETCH { my $self = shift; return ${ $self } ++; } package Main; my @arr = qw{ a b c d e }; tie my $inc, q{Incrementor}; say join $inc, @arr; say q{-} x 20; say join $inc, @arr;