package Redirect_Hash; sub TIEHASH { my ($class, $prefix) = @_; $prefix = 'redirect_' unless defined $prefix; my $self = [$prefix, {}]; bless $self => $class; } sub STORE { my ($self, $key, $value) = @_; my ($prefix, $hash) = @$self; if (index($key, $prefix) == 0) { my $truncated = substr($key, length($prefix)); $hash->{$truncated} = $value unless exists $hash->{$truncated}; } $hash->{$key} = $value; } sub FETCH { my ($self, $key) = @_; my ($prefix, $hash) = @$self; $hash->{$key}; } #### tie %h => Redirect_Hash; $h{redirect_name} = 'boondoggle'; print $h{name}, "\n"; # prints 'boondoggle' $h{name} = 'Fred'; print $h{name}, "\n"; # still prints 'Fred' print $h{redirect_name}, "\n"; # still prints 'boondoggle'