
593 A.2d 666 (1991)
STATE of Maine
v.
Jimmy HUTCHINSON.
Supreme Judicial Court of Maine.
Submitted on Briefs June 20, 1991.
Decided July 17, 1991.
Michael P. Cantara, Dist. Atty., David Gregory, Asst. Dist. Atty., Alfred, for plaintiff.
Craig Gardner, Gardner, Gardner & Murphy, Saco, for defendant.
Before McKUSICK, C.J., and ROBERTS, WATHEN, GLASSMAN, CLIFFORD, COLLINS and BRODY, JJ.
BRODY, Justice.
Defendant Jimmy Hutchinson appeals from a portion of his sentence handed down in the Superior Court (York County, Brennan, J.) after he was convicted of one count each of rape, 17-A M.R.S.A. § 252 (1983), and gross sexual misconduct, 17-A M.R.S.A. § 253 (1983). Hutchinson contends that the court abused its discretion in prohibiting contact with children as a condition of his probation. We modify the judgment and affirm it as modified.
Hutchinson was indicted on one count of rape and three counts of gross sexual misconduct for incidents that allegedly occurred in Sanford in 1988 and involved two children, ages ten and five. He pleaded guilty to the rape charge and one count of gross sexual misconduct in exchange for the State's dismissal of the other two counts. Following his conviction, the court sentenced him to concurrent terms of fifteen years, with all but eight years suspended, and six years of probation. The court orally ruled that as a condition of his probation Hutchinson was to have "no contact direct or indirect with the children." (Emphasis added). On the written order of probation, however, the above condition was recited as "no contact direct or indirect with children." (Emphasis added).
Hutchinson takes issue on appeal with the court's written order. He does not *667 argue that the court abused its discretion in prohibiting contact between him and the two children involved in this case. He contends, rather, that prohibiting contact with all children impermissibly goes beyond the court's understandable concern for the welfare of the victims.
Because a challenge to a sentence is cognizable on direct appeal only if it "addresses the legality of the sentence and alleges an infirmity appearing affirmatively from the record," State v. Parks, 544 A.2d 1269, 1271 (Me.1988), Hutchinson's appeal must be based on the theory that the contested portion of his sentence is illegal. This argument must fail. Where a discrepancy exists between the oral pronouncement of sentence and the written judgment and commitment, it has long been the law that the oral pronouncement of sentence controls, and we may examine the record as a whole to determine the actual decision made by the sentencing court notwithstanding any inaccuracy reflected in the written judgment. State v. Brydon, 454 A.2d 1385, 1388 (Me.1983).
Contrary to Hutchinson's contentions, the court did not abuse its discretion in sentencing him. The record is clear that in imposing the condition of probation the court had in mind not all children but only the two children whom Hutchinson had victimized. Said the court:
The childrenand I think I will impose as a condition no contact direct or indirect with the children as a condition of probation. That would, reasonably should leave the children in a position where they will be, they will obtain their majority, they will be adults at least in terms of law by the time Mr. Hutchinson is not being supervised by the Department of Corrections.
It is obvious from the court's oral pronouncement that the written condition of probation is the result of a clerical error and incorrectly reflects the court's actual decision.
Where, as here, the record is clear, the Law Court may make the necessary correction pursuant to M.R.Crim.P. 50. See State v. Brydon, 454 A.2d at 1388 (correcting written judgment pursuant to former Rule 36, the predecessor of Rule 50). Accordingly, the written order of the Superior Court is modified to substitute "the victims" for "children" in the condition of probation.[1] As pronounced orally and corrected in written form, Hutchinson's sentence is legal.
The entry is:
Judgment modified to substitute "the victims" for "children" in the condition of probation and, as so modified, affirmed.
All concurring.
NOTES
[1]  An appeal was not necessary in this case. Hutchinson could have obtained the same relief by filing an appropriate motion in the Superior Court.
