They are different wars in different regions, with different challenges. But as the war in Iraq winds down, there is a lot the U.S. military can learn and apply to Afghanistan, from how to deal with contractors to when to draw down troops.
Many practices will need to be adapted to a different terrain and environment. Unlike Iraq, the war in Afghanistan is often fought in a rural, mountainous region with a decentralized leadership.
But the Pentagon has already shifted some of its strategy from Iraq to Afghanistan - even down to installing Gen. David Petraeus as commander in Kabul after years of running the show in Baghdad.
"You need the population to believe that they will be protected," Gen. Ray Odierno, the departing U.S. commander in Iraq told Pentagon reporters last month. "And how you do that in Afghanistan is probably different than how you do it in Iraq. But the way you go about it in doing the assessment is the same."
Here are some of the lessons the U.S. has learned, or can learn, from Iraq, according to interviews with the military, diplomats and experts.
1. Be Careful about Contractors.
In September almost three years ago, private security guards with Blackwater Worldwide opened fire in Nisoor Square in Baghdad with what U.S. prosecutors called little or no provocation, killing 17 Iraqis. It was a symbol of contracting spun out of control in Iraq, and it led the Pentagon and Congress to crack down on the extent to which war zone duties could be outsourced to private firms.
It's not feasible to operate entirely without private contractors - the U.S. used them even in World War II, and contractors have saved many lives in both Iraq and Afghanistan. But the U.S. is learning that they need to be better vetted and regulated, and possibly reduced in number.
Already, contractors in Afghanistan are subject to local law, while in Iraq foreign contractors were immune from prosecution under local law for years. There are about 95,000 contractors in Iraq and 112,000 in Afghanistan, of which private security guards make up between 10 and 15 percent.
Paying for private security guards also is becoming a point of contention in Afghanistan, where President Hamid Karzai often complains about civilian killings by security contractors - some of whom run "recon by fire" patrols of shooting into hostile villages to prevent attacks.
Between 2003 and 2009, the latest data available, U.S. taxpayers paid $5.9 billion for private security contractors to protect Defense and State department employees in Iraq, according to government auditors. A similar cost analysis is under way in Afghanistan.
2. Build partnerships with locals.
One of the biggest successes of the Iraq war was to turn Sunni insurgents against al-Qaida by creating and funding local militias that allied with U.S. troops. These Sahwa - Arabic for Awakening, or commonly known as the Sons of Iraq - brought terrorist networks to a heel in key battlegrounds in 2007 and 2008 in part by putting a local face on military actions.
Petraeus is now trying to bring that strategy to Afghanistan, in part by forming local police forces to let villagers protect themselves against the Taliban in areas where soldiers can't be spared.
But carrying out and maintaining the strategy is shaky in both places. Al-Qaida is tempting Sahwa to abandon posts with payments of about $100 a month more than what the Iraqi government is paying them. And critics fear local police will fall under the control of Afghan warlords and question the wisdom of handing out weapons in the middle of a war.
3. Train local troops.
Training and equipping Iraqi forces, a $22 billion endeavor so far, has been a vigorous part of the U.S. mission almost from the beginning of the war. The aim is to minimize civilian casualties, as well as spend more time on the streets and less at checkpoints, as part of building more trust between Iraqi security forces and the communities they protect. Doing so could make tipsters out of residents, and in turn, help local forces collect more intelligence on insurgents.
U.S. commanders in Afghanistan also are following that tack, although they did not focus on rebuilding local forces until about a year ago.
They are trying to recruit Pashtuns to even out the overwhelming number of Tajiks in security forces. That's a careful plan to avoid the mistake of the U.S. deBaathification policy that forced thousands of Sunni soldiers out of the Shiite-dominated Iraqi army and into unemployment lines - and some into the insurgency.
"Emerging Afghan forces will in time assume responsibility for their own security," said John Nagl, president of the Center for a New American Security in Washington and an Iraq war veteran. "Getting to that point will be no easier in Afghanistan than it was in Iraq, but it can be done."
4. Watch the Clock.
The Iraq surge worked as well as it did because it invigorated the Sahwa movement and gave people the courage to break with insurgents. If the deadlines are too early, the insurgents wait you out and local partners can't handle the situation.
A security agreement between Baghdad and Washington calls for all U.S. troops out of Iraq by the end of 2011. That's led President Barack Obama to independently order this month's troop drawdown to 50,000 soldiers. Similarly, Mr. Obama has called for U.S. troops to start coming home from Afghanistan by summer 2011.
Such deadlines ultimately aim to end the U.S. military presence in both countries - giving respite to stretched-thin troops while pacifying Democrats in Mr. Obama's base who didn't want to ramp up in the first place. But they also give insurgents a timeframe to wait out the departures and launch more attacks.
In Iraq, despite plans to draw down in 2003 and again in 2006, the U.S. reversed itself with the surge that put nearly 170,000 troops on the ground at the end of 2007. That show of commitment, combined with commanders telling tribal leaders that the U.S. was staying, helped persuade Sunni tribal leaders to break with al-Qaida.
5. Treat prisoners like people.
One of the biggest failures in Iraq -and the one that most hurt the U.S. worldwide image - was detainee abuse at the Abu Ghraib prison outside Baghdad. Pictures of grinning U.S. soldiers posing with naked men on leashes or in painful and sexually humiliating positions helped insurgents recruit followers for revenge.
Congress since has banned harsh interrogation techniques of detainees and expanded some legal rights for detainees swept up on battlefields in Iraq and Afghanistan, since they are not considered by the U.S. to be prisoners of war.
The review process of Afghan detainees held at the Bagram Air Field prison is far more transparent than it initially was in Iraq. To be sure, much of what happens to high-value detainees held in U.S. facilities remains secret, and only recently have prisoners been given access to lawyers. Officials now are considering holding trials to end the indefinite imprisonment of Afghans suspected of insurgent ties.
6. Sign up more soldiers sooner.
The U.S. now has three times as many forces in Afghanistan - nearly 100,000 - than it had at the start of 2009. It's clear to most analysts that both wars should have been fought with more troops early on. It wasn't until the 2007 surge in Iraq - going from 137,000 troops to a peak of 166,300 in 10 months - that the war finally began to turn in favor of the U.S.
The dusty western Iraqi town of Haditha illustrates the need for enough military troops upfront to stay and fight rather than go back later.
U.S. Marines thought they had all but rooted out al-Qaida from Haditha in 2004, and pulled out of the city to let the local police forces take over. But insurgents crept back within months, launching unending attacks and executions and devastating the police force. That forced U.S. troops to return to Haditha in large numbers, hunkering down for years until the violence was under control.
The lesson played out on a bigger stage in Afghanistan, where U.S. forces were successful in defeating the Taliban in their initial 2001-02 push but pulled back too early to make the victory stick. Distracted by the Iraq invasion, the Pentagon took its focus off Afghanistan, giving the Taliban ample room to quietly return. As a result, 30,000 more troops have been sent to keep the Taliban from turning Afghanistan back into an al-Qaida haven.
7. Keep expectations low.
Then-President George W. Bush took a pounding in 2003 when, under a "Mission Accomplished" banner, he declared major combat operations in Iraq were over, only six weeks after the invasion. More than seven years later, President Barack Obama is hoping to mark that milestone this month.
The war in Iraq has been longer, costlier, bloodier and far more unpredictable than most people expected. Even so, many Americans forget that Afghanistan is the longer war, having started shortly after the Sept. 11, 2001 attacks.
Petraeus's strategy is always to ratchet down expectations - he emphasizes the difficulty of operations, so that it's easier to then look successful. In Afghanistan, the Mr. Obama administration has shied away from even using the term "winning the war," underscoring uncertainty if it can be done or even what a victory might look like.
That may be one enduring legacy of Iraq - that the U.S. has learned to be far more careful before declaring victory.