Two of the country's largest food companies have agreed to merge in a deal put into place with the help of dozens of lawyers across four law firms.

Pittsburgh-based H.J. Heinz Co. announced Wednesday its agreement to merge with Chicago-area-based Kraft Foods in a deal that would create the fifth largest food and beverage company in North America and marry brands such as Heinz Ketchup and Philadelphia Cream Cheese.

Warren Buffett's Berkshire Hathaway and investment firm 3G Capital are helping to finance the deal. The two entities purchased Heinz in June 2013 and, according to The New York Times DealBook, immediately identified Kraft as a potential merger partner.