So, we all know how many times the Roman legion got its ass kicked by the Hellenistic phalanx, but, just in case your memory is shoddy, let me remind you:
The first ass-woopings came during the Pyrrhic War, where Pyrrhus defeated the Romans in southern Italy twice, at Heraclea and Asculum, then crossed over into Sicilly where he evicted the Carthaginians, went back to Italy where he also won round three at the battle of Maleventum with a daring night attack that destroyed half the Roman force before they had a chance to form a battle line, and this despite lacking in previous Samnite support.
It's only because of his later death in Macedonia that the Romans were able to renege on their treaty and pick up the crumbling pieces of his empire, only facing regular local Greek hoplites from southern Italia.
Rome didn't really face an Alexandrian-esque army for another 75 years whilst they conquered Illyria and the western Mediterranean, tiny skirmishes in the 210s against the Macedonian navy notwithstanding. Then came the battle of Cynoskephale in 197 B.C., where a combined Roman-Greek force failed to dislodge a Macedonian phalanx that had formed up on high ground, with losses so heavy, that the Romans agreed to a treaty.
Of course, the Hellenes continued to figth among themselves, and when the Seleucids finally appeared to conquer Macedonia, the Romans once again intervened, achieving their one and only victory against the phalanx. Of course, half the "Roman" army were either Macedonian phalangites or Greek hoplites, and they outnumbered the Seleucids about 5-3, so I'm not sure how much this counts...
The final battle occured a year later, when the Romans, emboldened by their success, crossed into Asia Minor, linked up with their Pergamese allies and fought the Seleucid King at a place called Magnesia. Once again the Phalanx in the center held, and Hellenistic cavalry won on both flanks, sealing the deal.
This war, and the Macedonian civil war two years later, had so devastated Macedonia though, that Rome and her Greek allies were able to occupy the whole Kingdom without even much of a fight after assasinating the Macedonian King, his tiny remnant army deserting him.
Of course, clashes between Greek city-states (fighting in the traditional hoplite style) and Romans continued for about eight decades afterwards whilst the Seleucids were content staying on their side of the Hellespont, milking Egypt for its wealth and fighting the periodic rebellions in Asia Minor and the Far East.
The last fight between a Roman manipular legion and a Hellenistic phalanx was more of a joke than anything else, coming in two years after the sacking of Rome by the Cimbri and the fracturing of their state. Heavily outnumbered more than 4-1, remnant Roman forces in Greece yielded to superior Seleucid numbers, with official Seleucid chroniclers barely mentioning the event in passing, more concerned with the battle against the Greeks that followed.
So, what would have been needed for the legion to best the phalanx? Obviously, its inherent design was flawed, only being good for beating up antiquated hoplite armies or disorganized barbarians, but maybe with a bit of luck, the Republic could have achieved dominance over the eastern Mediterranean, as opposed to the eastern tyrants?