use v5.12; sub autobless ($) { ref $_[0] eq 'HASH' and bless $_[0] => 'Hash'; ref $_[0] eq 'ARRAY' and bless $_[0] => 'Array'; return $_[0]; } sub Hash::AUTOLOAD { return unless $Hash::AUTOLOAD =~ /::(\w+)$/; autobless $_[0]{$1}; } sub Array::AUTOLOAD { return unless $Array::AUTOLOAD =~ /::_([0-9]+)$/; autobless $_[0][$1]; } my $h = { foo => 1, bar => 2, doz => 3, quux => [ 4, {quuux => 5} ]}; autobless $h; say for $h->foo, $h->bar, $h->doz; say $h->quux->_0; say $h->quux->_1->quuux;