my %subs = ( path => [ @{$session{hierarchy_path}} ] ); $subs{bottom_path_term} = ${pop(@{$subs{path}})}{term}; if (@{$subs{path}}) { delete $subs{path}[$#{$subs{path}}]{id}; } else { delete $subs{path}; } #### Before: 'hierarchy_path' => [ { 'id' => 0, 'term' => 'Top of Hierarchy' }, { 'id' => '57000', 'term' => 'Education' } ], After: 'hierarchy_path' => [ { 'term' => 'Top of Hierarchy' }, { 'id' => '57000', 'term' => 'Education' } ],