for my $href ( @data ) { my $copy_ref = { %$href }; delete $copy_ref->{sex}; push @{ $data2->{$href->{sex}} }, $copy_ref; }