sub string_to_struct { my $string = shift; my ($var, $keys) = split /-/, $string, 2; $keys = "-$keys"; # you could use a lookahead in the split, but in my experience they break on older Perl 5s. return 0 unless ( $var eq "safe" or $var eq "alsosafe" ); $change{$var}++; # global no strict refs; my $ref = $$var; # reference to the original. can alter the original use strict refs; return deref($ref, $keys); } sub deref { return \$_[0] unless $_[1] =~ s/^-([\w_]+)//; deref ($_[0]->{$1}, $_[1]); } #### struct_to_string($safe,$safe->{foo},$safe->{foo}{bar});