Hidden Markov models (HMMs) provide a general framework for expressing primary sequence consensus. HMMs can effectively be used to model and align protein families, and to search data bases. HMMs, however, have a large number of parameters. When only few sequences are available for model fitting, additional prior information must be incorporated into the models. We derive a simple algorithm that directly incorporates prior information provided by substitution matrices into the HMM learning procedure.