in reply to returning a tied variable

You can do it if the variable to tie is passed as an argument, since the elements of @_ are aliases (not copies) of the arguments.

sub ModName::TIESCALAR { my $class = shift; my $self; return bless(\$self, $class); } sub test { tie $_[0], 'ModName'; } my $var; print(tied($var) ? 'tied' : 'not tied', "\n"); # not tied test($var); print(tied($var) ? 'tied' : 'not tied', "\n"); # tied

Otherwise, you have to return it as a reference.

sub ModName::TIESCALAR { my $class = shift; my $self; return bless(\$self, $class); } sub test { my $var; tie $var, 'ModName'; return \$var; } my $ref = test(); print(tied($$ref) ? 'tied' : 'not tied', "\n"); # tied

You can't make a copy of a tied variable. You'll only be making a copy of the value its FETCH returns.

sub ModName::TIESCALAR { my $class = shift; my $self; return bless(\$self, $class); } sub ModName::FETCH { } tie my $src, 'ModName'; print(tied($src) ? 'tied' : 'not tied', "\n"); # tied my $dst = $src; print(tied($dst) ? 'tied' : 'not tied', "\n"); # not tied