Section 11A. If a defendant is charged with a crime for which more severe punishment is provided for second and subsequent offenses, and the complaint or indictment alleges that the offense charged is a second or subsequent offense, the defendant on arraignment shall be inquired of only for a plea of guilty or not guilty to the crime charged, and that portion of the indictment or complaint that charges, or refers to a charge that, said crime is a second or subsequent offense shall not be read in open court. If such defendant pleads not guilty and is tried before a jury, no part of the complaint or indictment which alleges that the crime charged is a second or subsequent offense shall be read or shown to the jury or referred to in any manner during the trial; provided, however, that if a defendant takes the witness stand to testify, nothing herein contained shall prevent the impeachment of his credibility by evidence of any prior conviction, subject to the provisions of section twenty-one of chapter two hundred and thirty-three. If a defendant pleads guilty or if there is a verdict or finding of guilty after trial, then before sentence is imposed, the defendant shall be further inquired of for a plea of guilty or not guilty to that portion of the complaint or indictment alleging that the crime charged is a second or subsequent offense. If he pleads guilty thereto, sentence shall be imposed; if he pleads not guilty thereto, he shall be entitled to a trial by jury of the issue of conviction of a prior offense, subject to all of the provisions of law governing criminal trials. A defendant may waive trial by jury. The court may, in its discretion, either hold the jury which returned the verdict of guilty of the crime, the trial of which was just completed, or it may order the impanelling of a new jury to try the issue of conviction of one or more prior offenses. Upon the return of a verdict, after the separate trial of the issue of conviction of one or more prior offenses, the court shall impose the sentence appropriate to said verdict.