Place the headboards next to each other in the order they will eventually be installed. Make a series of marks 8 inches in on both headboards from the point of contact where the two headboards meet. Turn these marks into a line, and then use the saw to remove these 8 inches from each headboard. Sand the newly cut edges with sandpaper to smooth them out.
Make a mark every 12 inches on the side of each headboard which will be attached together, using the tape measure. Press the headboards together to ensure the markings are the same.
Drill a hole in each marking using a drill bit that is exactly the same diameter as the pegs. Drill the hole a little bit deeper than half the length of the pegs.
Insert a peg into each hole on one of the headboards. Slide the headboards together until the pegs push all the way into their holes in the opposing headboard. Wiggle the headboards to ensure that the they are tightly attached.
Position the 2-by-4 on the rear of the headboards, spanning the joint between them. Pre-drill four evenly spaced holes through the 2-by-4 and into the headboard on each side of the joint for a total of 8 holes, being careful not to puncture the front surface of the headboards. Attach the board to the headboard using wood screws for extra stability.