Browsing through FTrain's past entries I ran across his Emacs Notepad a collection of tips and scripts. Having spent a past life (well, past job) in Emacs this brought back fond memories. Be sure to scroll down to the section on Using Perl to Interface with Emacs.