my $names = [ { id => 'X01', item => 'Widget', }, { id => 'Y02', xref => 12, yref => 13, }, { item => 'none', }, { id => undef, }, ]; #### foreach my $a (@{ $names }) { push(@ids, $a->{id} // ()); } #### my $ids = join ',', map { $_->{id} // () } @$names;