# ... push @out_field_heap, @field, "\n"; } # single join over the whole batch my $out_buffer = join "|", @out_field_heap; # but that means we surrounded the newlines with pipes, # so fix em $out_buffer =~ s/\|\n\|/\n/g; print OUTPUT $out_buffer; }