"I think there has been in the past a view on the part of Pakistan that their primary rival, India, was their only concern," Obama said at a joint press availability with the visiting Afghan President Hamid Karzai.
"I think what you've seen over the last several months is a growing recognition that they have a cancer in their midst; that the extremist organisations that have been allowed to congregate and use as a base the frontier areas to then go into Afghanistan -- that now threatens Pakistan's sovereignty," Obama said in response to a question.
"Our goal is to break down some of the old suspicions and the old bad habits and continue to work with the Pakistani government to see their interest in a stable Afghanistan which is free from foreign meddling," he said.
The US President stressed on the need for Afghanistan, Pakistan, United States and the international community to work together to flush out extremists from those regions.
"I am actually encouraged by what I've seen from the Pakistani government over the last several months," Obama said.
"But just as it's going to take some time for Afghanistan's economy, for example, to fully recover from 30 years of war, it's going to take some time for Pakistan, even where there is a will, to find a way in order to effectively deal with these extremists in areas that are fairly loosely governed from Islamabad," he said.
He praised the recent efforts made by Pakistan to fight against extremist elements inside the country.
"You know, part of what I've been encouraged by is Pakistan's willingness to start asserting more control over some of these areas, but it's not going to happen overnight.
"And, you know, they have been taking enormous casualties, the Pakistani military has been going in fairly aggressively, but this will be an ongoing project," he said.
On his 45-minute meeting with Karzai at the Oval office, Obama said that two leaders discussed that the ultimate way to secure Pakistan is to secure Afghanistan.
"The only way that Afghanistan is secure is if the sovereignty, the territorial integrity, the Afghan constitution, the Afghan people are respected by their neighbours," he said.
"We think that that message is starting to get through, but it's one that we have to continue to promote," Obama said.