I'm not sure I understand your description correctly... I'm assuming you're relocating a double wall vent pipe / changing location of some appliance within a house / garage? What do you mean by "is it OK to connect it back in the attic"?
You have to connect it back to the attic section or go straight up and create another hole in the roof / decking surface. Double wall vent pipe / B-vent have different locking mechanisms so you have to go with the same manufacturer (as the existing one) when purchasing two elbows and a piece between them. Do not use any screws on connections unless they are there by design.
The trick will be to find proper length of a vent pipe to create an offset and fit perfectly in that 5' space. Remember to keep a minimum of 1/4" raise per linear foot of that new section towards the roof penetration.
Unfortunately I can't provide you with more suggestions because I don't have any details about this installation (check the link above).