The Republican legions, including those that faced Hannibal, were tactically handcuffed. Hannibal's great mobility came from the heavy reliance he placed on cavalry (which is something the Romans were never good at). In the Republic, the 'conscript' (I use that term to reflect that the armies were not full time professionals) Roman armies were still partially based on the old Greek phalanx system, which historically was very immobile. Lack of consistency through armies being assembled as needed, rather than constant training, etc., limited the capability of military tactics during that time.
After the reforms of Marius, through the civil war period and into the Augustan Age, the Romans developed a professional standing army. The professional legions were the most mobile tactical infantries in the ancient world, where each piece (cohort, century, etc.) was capable of independent operation. The Imperial Legions (or Post Marian) were uniform in principle and strategy, meaning gear and training were the same for each soldier. One entire cohort (6 in a legion) could peel off the main body to flank or circumvent an enemy, and the cohesion of the whole wouldn't be compromised.
In the Republican army, flanking was, for the most part, unheard of. Most battles in that era were straight on head to head engagements. When Hannibal came to Italy, his cavalry was able to run around the tactically inferior Romans at will, and his superiority as a battlefield general was established. The Romans however, learned a great deal from Hannibal, and his success began to change the way the Romans looked at warfare. The world can really give a great deal of credit to Carthage for Rome's eventual dominance of the western world.