use 5.020; package Sphere; sub new { my $class = shift; my $self = { location => { x => 1, y => 2, z => 3 }, radius => 100, }; bless $self,$class; } sub get_location { my $self = shift; return $self->{location}{shift()}; } package main; my $sphere = Sphere->new; my $y = get_location('y'); say $y;