BBEdit has the ability run both applescripts and perl programs. If I wanted to to this, I would install
Perltidy and write a small script to run Perltidy on the current buffer. The excellent BBEdit documentation should be able to show you how to do this.