for my $h (\%a1, \%a2) { print join ',', map{ exists $h->{ $_ } ? $_ : '##' } @a; }