HMS was a registry prefix that was used both in historical Earth naval ships and in starships.
The HMS prefix originated in the British Royal Navy, where it was used to denote warships as early as the 18th century. Some notable sailing ships with the prefix include HMS Defiant, HMS Enterprize, and HMS Victory.
In the 21st century the Royal Navy operated a submarine named HMS Clement with the registry, suggesting it continued to be used at least until then. (ENT: "Minefield")
Later the prefix was also used in at least two early 22nd century Earth starships of unknown affiliation, HMS New Zealand and HMS Lord Nelson, both DY-class ships. (TNG: "Up The Long Ladder")
The name HMS Bounty was given to a Klingon Bird-of-Prey commandeered by James T. Kirk in 2285. It was named as such in a fit of historical irony, as the original Bounty, a Royal Navy ship, had been taken over by mutineers – a situation similar to that the former USS Enterprise crewmembers found themselves in that year. (Star Trek IV: The Voyage Home)
HMS Pinafore was an Earth operetta by Gilbert and Sullivan about a sailing ship of the same name. (Star Trek: Insurrection)