my $fh = defined $hash{$ita}[0] && defined $hash{$ita}[1] ? $out : $out1; print $fh "$ita => ", join(',', map { $_ // () } @{ $hash{$ita} }), "\n"; #### 17:42 >perl -MData::Dump -wE "my @c = qw(a e i o u); @c = map { $_ eq 'i' ? undef : $_ } @c; dd \@c;" ["a", "e", undef, "o", "u"] 17:44 >perl -MData::Dump -wE "my @c = qw(a e i o u); @c = map { $_ eq 'i' ? () : $_ } @c; dd \@c;" ["a", "e", "o", "u"] 17:44 > #### print $fh "$ita => ", join(',', grep { defined } @{ $hash{$ita} }), "\n";