It all depends on what period you're talking about. Through most of the 20th century, Boston was served by only three major railroads: the Boston & Albany (New York Central), Boston & Maine, and New Haven. There were also a few freight-only short lines, e.g., the Union Freight RR, on Atlantic Ave., and the Fore River RR, which served the Quincy shipyard. And, of course, the was the famous narrow gauge, passenger-only Boston, Revere Beach & Lynn, now occupied in part by MBTA's Blue Line.
But before 1900, there were several others that were folded into the B&M and NewHaven systems, notably the Fitchburg RR and Eastern RR (B&M), the Old Colony (which had leased the Boston & Providence), and New York & New England (both to the NH). And earlier, there were even more, including the pioneering Boston & Lowell (B&M), Boston & Worcester (B&A), and Boston & Providence (NH, as noted). Finally, there was the Boston Terminal Co., a joint NYC-NH company that owned and operated South Station.
The Boston & Albany actually ceased to exist as an operating company in 1900, when the NYC leased it, and in the early years of the lease its equipment was lettered NYC&HR. But stubborn local Boston sentiment, plus some insensitive actions by NYC's first general manager, led to a public relations retreat, and equipment and structures were relettered B&A. This policy remained until after WWII, when NYC-lettered equipment began sneaking in, and in the diesel era everything was lettered NYC. But from an operating viewpoint, the B&A was part of NYC in all respects. The corporate shell of the B&A remained simply to receive lease payments from NYC and distribute them to its minority stockholders.