for my $href (@data) { push @{ $data3->{ $href->{sex} } }, { map 'sex' eq $_ ? () : ( $_ => $href->{$_} ), keys %$href }; }