The following pertains to the U.S. only.
“Contempt of court” arises from the judge’s power to maintain order and decorum in his or her courtroom and from an individual’s obligation to cooperate with the legal process. So there are two broad types of contempt of court – willful disrespect of of the dignity of a court, and willful disobedience of a lawful order of a court.
Historically, the judge’s authority to hold someone in contempt of court has been considered inherent – that is, it is something you can do because you are de judge. (The dignity of a judge’s position necessarily encompasses the right to insist that dignity be respected; and the authority of a judge’s orders necessarily includes the right to enforce those orders.) These days, though, most states (AFAIK) have made explicit a judge’s authority to hold people in contempt by setting it out in the state statutes. Contempt is generally a civil matter – meaning it results in the imposition of a fine, not in the bringing of criminal charges – although in egregious cases charges of criminal contempt may be brought.
Perjury, OTOH, is specifically the act of making a false statement under oath, generally in a court of law. Perjury is a big deal. (Not to imply that contempt of court is not a big deal too, but perjury is a way bigger deal.) Perjury is a crime, in all U.S. jurisdictions (AFAIK). In my jurisdiction, perjury in the first degree is a felony. Perjury may not appear to be a contempt of court in a given specific case, because it may not offend the dignity of the courtroom and or involve defiance of a court order, but it is in theory always a contempt, because lying under oath undermines, and offends the dignity of, the proceedings.
You have to be in court (or otherwise under oath, like at a deposition) in order to commit perjury. You only have to disregard or defy a court order in order to be held in contempt of court. If you get a summons for jury duty and you disregard it, it is possible you will be cited for contempt of court. Most contempt citations IME arise from disregarded or defied court orders – people who are summoned or subpoena’ed and don’t show up. It’s rare for a person to be held in contempt for in-court behavior (with the exception of certain criminal defendants) though I myself once heard opposing counsel lose his head, call the judge a horse’s ass, be cited for contempt, write a check for $500 for the contempt citation, move to have the judge recuse himself, have his motion denied, call the judge a horse’s ass again, and be escorted from the courtroom to cool his heels in a jail cell. All in less than 10 minutes. (True story.)
Judges do tend to be zealous of their dignity (especially IME federal judges), but personally I think that’s appropriate in that they are the gatekeepers for the Rule of Law, which I have the utmost respect for.