He took part in the operations off Derne, and was highly commended for his conduct. In the autumn of 1806 he returned home, and served at home stations until 1809, when he got his first command. This was a smart little schooner, the Revenge, of fourteen guns.

At that time the occurrences which led to the war of 1812-15 were taking place, and Perry soon had a chance to show his determination to maintain the dignity of the flag he flew. An American vessel had been run away with by the English captain who commanded her and who had hoisted British colors over her. Perry determined to take possession of her, although two small British cruisers lay near her. This he did, supported by three gunboats. The British cruisers, appreciating the justice of his conduct, did not interfere, although Perry had no means of knowing whether they would or not and took all the chances. As he was carrying the vessel off, he was met by a British sloop-of-war, and her captain sent a boat, with a request that Perry should come aboard. This Perry flatly refused, and, determined that his ship should not be caught unprepared as the Leopard caught the Chesapeake in 1807,[18] he sent his men to quarters, and made every preparation to resist; but the British ship passed on, and no collision occurred. In January, 1811, Perry had the misfortune to lose the Revenge by shipwreck off Watch Hill, in Rhode Island; but the court of inquiry which investigated it acquitted him of blame, and praised his conduct at the time of the accident.

When war was declared with Great Britain, Perry was in command of a division of gunboats at Newport; but finding there was little chance of seeing active service in that duty, he asked to be sent to the lakes, where Commodore Chauncey was preparing to dispute the possession of those great inland seas with the British.

In the spring of 1813 Perry arrived at Lake Erie, and entered upon his duties. The small fleet to oppose the British had to be constructed in the wilderness, on the shores of the lake; and men and material had to be transported at great labor and cost from the seaboard.

Perry showed the utmost skill, energy, and vigilance in his arduous work, and built and equipped his little squadron in a manner most creditable to himself and his subordinates.

The land forces, operating together with the seamen and marines, got command of the Niagara River; but a little British squadron guarded the mouth of the river, at which there was a bar which it was thought unlikely the Americans could pass and so get into the lake itself. Perry, however, watched his chance, and on a Sunday afternoon in August, 1813, to his surprise, he found the British squadron had disappeared. It was said that the British commander, Barclay, had gone over to the Canadian side to attend a dinner, thinking the Americans could not possibly get over the bar before his return. But Perry and his officers and men went to work, and by the most arduous labor they got all the vessels into the lake before Captain Barclay returned. Once in the lake, the Americans were much stronger than the British, and Perry determined to go in search of the enemy. He had much sickness on his little squadron, and was ill himself, so that it was not until early in September that he was prepared to fight. Meanwhile the British, although having only six vessels to oppose to Perry's nine, undauntedly sought the conflict, and on the morning of the 10th of September, while Perry was in Put-in-Bay, he saw the little British squadron standing in the offing. Perry had two brigs, the Lawrence,—his own flagship, named for the brave Lawrence,—and the Niagara, each of which carried twenty guns; and he had five smaller vessels. Captain Barclay had the Detroit,—his flagship, of nineteen guns,—the Queen Charlotte, of seventeen guns, and four smaller vessels.

The wind was light and variable, so that the American vessels came out slowly; but the little British squadron waited with their topsails to the mast, until a quarter to twelve, when the first shot was fired by the Detroit. In a very little while the action became general, each American and British vessel bravely doing its best to get alongside its enemy. It was the effort of the gallant commanders of the American and British squadrons to fight flagship to flagship; and in doing this, Perry, in the Lawrence, drew ahead of his column, and concentrated upon his ship the fire from the Detroit and two other vessels. The British fought their batteries with unusual skill, and the result soon was that a dreadful slaughter took place on the Lawrence's decks, her guns were silenced, and she was so much cut up that she was totally unmanageable. But Perry, with indomitable courage, continued the fight. He himself, with the help of the purser and the chaplain, fired the last gun available on the Lawrence. Her consort, the Niagara, approached about this time, the wind sprang up, and Perry, seeing that the battle was passing ahead of him, determined to abandon his own unfortunate ship and make for the Niagara. He ordered a boat lowered, and, taking with him his brother, a little midshipman of thirteen years old, he was rapidly pulled to the Niagara. Once on board of her, he bore up, and soon got her into a position to rake both the Detroit and the Queen Charlotte with fearful effect. These two vessels, after an heroic defence, were compelled to strike, while the seven smaller American gunboats soon overpowered the four British ones. The Detroit, however, before striking had forced the Lawrence to haul down her colors; and the fight, as all the others during this war, was as creditable to British as to American valor.

The first news of the victory was in Perry's celebrated despatch: "We have met the enemy, and they are ours." The news from the Canadian border had not always been gratifying, and on that account the American people were the more delighted at this success. Perry was given a gold medal and promoted to be a post-captain; for although he had been called commodore by courtesy, such was not his real rank at the time.

Perry had no further opportunity of distinguishing himself before peace was declared, in January, 1815. He obtained afterward some of the best commands in the navy, and in March, 1819, he became a commodore in fact, by being given the command of a squadron in South America destined to protect American trade in those quarters. He hoisted his broad pennant on the John Adams, and sailed in June. He reached the mouth of the Orinoco River in August, and, although it was in the midst of the sickly season, he determined to go up the river to Angostura. He shifted his flag to the Nonesuch, schooner, and sent the frigate to Trinidad.