my @hashloc = qw{ depTar name }; my $xml = { 'depTar' => { 'name' => 'c_p20', 'loc' => 'srvr1' }}; print $xml->{ $hashloc[0] }{ $hashloc[1] };