#!/usr/bin/perl $CONFIGS={}; string_to_struct("CONFIGS-hosting_plans-c-title","ctitle"); print $CONFIGS->{hosting_plans}{c}{title}; exit; sub string_to_struct { my $string = shift; my $val = shift; my ($var, $keys) = split /-/, $string, 2; # safety check would normally be here - removed for simplicity no strict refs; my $ref = $$var; use strict refs; my $pointer = $ref; my @a = split(/-/,$keys); foreach ( 0..$#a ){ $pointer->{$a[$_]} = ($_ == $#a) ? $val : {}; $pointer = $pointer->{$a[$_]}; } $ref; }