in reply to Join unless $var has already been joined?

Replace your foreach loop with this instead -
foreach my $key (sort keys %images) { my ($tapes, $img); my $client = $images{$key}->{'client'}; my $sched_type = $images{$key}->{'schedule_type'}; my $sched_name = $images{$key}->{'sched_label'}; my $policy = $images{$key}->{'policy'}; my $kb = $images{$key}->{'kbytes'}; # Create an array of tape records my @tapes; foreach (keys %{$images{$key}) { if (/copy_\d_frag_\d_id/) { push @tapes, $images{$key}{$_}; } } # Join tape id's in sorted order $status{$client}{$policy}{'tapes'} = join " ", sort keys %{{map {$_=>1} @tapes}}; }