in reply to Trying to make the code more clear and clean

This duplicates my understanding of your code without the temporary hash.
use strict; use warnings; use List::Util qw(uniq); use Data::Dumper; my $group = q(ABC1); my $value = q(xyz); my $href = { values=> [qw(abc xyz abc)], }; push @{$href->{test}}, {group=>$group}; $href->{test}[-1]{values} = ( defined $href->{"values"} ) ? [sort(uniq($value,@{$href->{"values"}}))] : $value ; print Dumper $href;
Bill