After a nearly four-hour hearing, U.S. District Judge John Gibney said that if the candidates thought the law was unconstitutional they should have challenged it when they first began their campaigns in the state rather than waiting until after they failed to qualify.

“In essence, they played the game, they lost, then they complained about the rules,” Gibney said.

Joseph Michael Nixon, an attorney for Perry, said no immediate decision was made on whether to appeal.

Perry sued last month after failing to submit enough signatures to get on the ballot. Former House Speaker Newt Gingrich, former Pennsylvania Sen. Rick Santorum and former Utah Gov. Jon Huntsman also failed to qualify and later joined Perry's lawsuit.

Only former Massachusetts Gov. Mitt Romney and Texas Rep. Ron Paul qualified for the March 6 primary ballot.

Virginia requires candidates to obtain the signatures of 10,000 registered voters, including 400 from each of the state's 11 congressional districts, to get on the ballot. The law also allows only Virginia residents to circulate petitions.

Perry claimed the residency requirement violated his free-speech and free-association rights by limiting the number of people who could carry his message in Virginia. Gibney agreed that the provision is likely unconstitutional, although he did not strike it down because the only question before him was the candidates' request for a preliminary injunction — not a trial on the merits.

“It's clearly a form of protected speech,” Gibney said of the right to circulate petitions.

The judge said that had the plaintiffs brought their lawsuit earlier, he or another judge could have issued an order allowing the use of nonresident petition circulators and perhaps the candidates would have gathered enough signatures to qualify.

Gibney disagreed, however, with the plaintiffs' claim that the 10,000-signature threshold — the highest in the nation — is overly burdensome and serves no compelling state interest.

The judge also said he was concerned that adding more names to the ballot at this late date would disrupt the electoral process. Attorneys for the State Board of Elections said at the hearing that adding the names would prevent elections officials from complying with a legal mandate to mail absentee ballots to military and overseas voters at least 45 days before the election — in this case, Jan. 21.

Meanwhile, for the second time of his presidential campaign, Perry messed up his list of three federal Cabinet departments he'd like to eliminate.

Related

In a radio interview conducted from South Carolina, Perry added a fourth agency to his previous list of three targeted for elimination — but forget one of his original three:

“Three right off the bat, you know, Commerce, Interior and Energy are three that you think,” Perry told Bill Edwards of WTKS radio in Savannah, S.C., according to ABC digital news reporter Arlette Saenz.

The one he forgot: the Education Department.

At a debate in Michigan, Perry famously said “oops” when he couldn't remember the third of the three agencies he vows to shutter as president. (It was the Energy Department.)

This time, he added the Interior Department to his target list. He hadn't mentioned closing the agency that regulates offshore drilling before.

“Was that a mistake?” reporters traveling with Perry asked his campaign spokesman.

“It shouldn't be surprising the governor is talking about another federal agency that needs to be looked at and cut,” spokesman Mark Miner responded, according to ABC.

The Associated Press and the Hearst Washington Bureau contributed to this report.