Every so often, a fatberg-esque blob of material called ambergris washes up on a beach.

These lumps, used to make perfume, can be worth thousands of dollars in countries where it is legal to collect them. Historically, hunters have trained dogs and even camels to sniff out ambergris.

Where it comes from has been less clear. Modern scientists knew that ambergris could be found within the bodies of sperm whales, but they weren’t sure about those pieces of jetsam found by beachcombers. But in a study published Wednesday in Biology Letters, researchers have extracted sperm whale DNA from washed-up ambergris, which is especially impressive because the studied samples floated adrift for years, aging under salt, sea and sun. The research could contribute a new understanding about the enigmatic substance and the endangered creatures that make it.

“The discovery that ambergris yields such good DNA preservation opens up new opportunities for studying both the use of this precious raw material and whale biology,” said James Barret, an archaeologist at the University of Cambridge who did not participate in the research.

Fresh ambergris smells fecal, musty. But once it ages, its scent is compared with fine tobacco, or the wood in an old church. The mother of the Abbasid Caliph Al-Muqtadir would melt it in oil; Catherine de Medici wore it in scented gloves; and ambergris has anointed English monarchs since 1626, including Queen Elizabeth II.