THE Juba river region, in Somalia, is hard country. Women are regularly eaten by crocodiles while fetching dirty water. The sandy farmland is either in drought or flooded. And the militants known as the Shabab, who rule the area, exact brutal justice. Your correspondent had to turn back from the town of Wajid (see map) this week because, within, a man was being beheaded. A day later, a clan leader was shot dead. As The Economist went to press, three more were to be beheaded in Wajid, and two more had suffered the same fate in a nearby village.

All were suspected of being “collaborators” with the internationally recognised, but largely powerless, transition government in Mogadishu that is protected by a small African peacekeeping force. It is led by Sharif Ahmed, a moderate Islamist, who once headed the Islamic Courts Union. This had imposed a tenuous calm in the city, but was swept from power by Ethiopian forces in 2006 because its erstwhile allies in the Shabab, or “Youth”, had ties with al-Qaeda. If anything, the intervention strengthened the Shabab and hardened their link with global jihadism—not least because of an influx of foreign fighters who see Somalia as the next battleground for holy war.

The Shabab now control most of south and central Somalia, and much of Mogadishu. Western security sources worry they could stage attacks outside the country, of the kind that destroyed the American embassies in Kenya and Tanzania in 1998.

The Shabab, for their part, have nothing but contempt for President Ahmed. “Even you [an infidel] are closer to us than he is," one stern-looking Shabab commander tells your correspondent. “He is far, far from us, because he has sold out his religion.” Dressed in jeans and sandals, and sporting a wispy beard, the commander asks not to be identified; even speaking to an unbeliever can invite retribution. Western security sources say many foreign militants are in the Juba valley. And the commander is happy to have them. “Colour makes no difference,” he says, “All Muslims are the same. They are welcome.”

There is a streak of pragmatism among the Shabab that is distinct from al-Qaeda. The Shabab guarantee the safety of the food convoys of the United Nations' World Food Programme (WFP). That said, there is an air of fear in Shabab-ruled areas such as Buale. Checkpoints are everywhere. Elders seem to be losing authority; they stick to resolving disputes over land and marriage. Residents are for the most part reluctant to talk. One tells the story of a 15-year-old boy who returned home to the Juba river after fighting with a ferocious Shabab unit in Mogadishu. When his mother pleaded with him not to return to the fighting, he threatened to kill her on the spot.

Not all those who bear arms in the name of Islam support the Shabab. Several hundred kilometres north-east of Buale, in the town of Dusamareb, Sheikh Omar Sharif Muhammad, a Sufi religious leader, has mobilised fighters to “liberate” Mogadishu from the Shabab. On July 1st, Somalia's Independence Day, a local crowd gathered to sing patriotic songs and raise the national flag, a white star on an azure background—a rare sight for a country without a working government since 1991. Some of the men from his movement, Ahlu Sunna Waljama, had shiny new Kalashnikovs; Sheikh Omar said they were not gifts from Ethiopia or America, both of which want to counter the backing given to the Shabab by Eritrea and private Arab donors.

Sheikh Omar's men do not have the strength to march on Mogadishu any time soon, but in several recent battles they have halted the northward advance of the Shabab. They claim to have killed all manner of foreign fighters, and to have recently intercepted two Canadians of Somali extraction sent out as suicide-bombers.

Security in the Galgadud, the desert region controlled by the militia, has improved. But the humanitarian situation is dire. WFP says 90% of the 400,000 people in the area need food aid to survive. The failure of the Gu rains, which fall between April and June, promises greater misery. Matters are made worse by the arrival of 60,000 people fleeing Mogadishu.

Some of the refugees are gathered in a compound near Sheikh Omar's base, among them Muhammad Hassey, who says he has moved house ten times over the years to escape fighting. He finally left Mogadishu when his two brothers and two sisters were killed by a mortar shell. Kadijo Hassan, an elderly lady, interrupts. “Mogadishu is unbelievable,” she says. “It is war. Everyone is crying there.”