my %function_for; my %scalar_ref_for; sub TIESCALAR { my ( $class, $function ) = @_; if ( ref $function ne 'CODE' ) { croak('Argument to tie must be a code reference'); } my $self = bless \do { my $anon_scalar }, $class; $function_for{ ident $self } = $function; $scalar_ref_for{ ident $self } = q{}; return $self; } sub STORE { my ( $self, @args ) = @_; $function_for{ ident $self }->(@args); } sub FETCH { my( $self ) = @_; return $scalar_ref_for{ ident $self }; }