File re-alignment



I have some VHDL files thatI'd like to "tidy up".
The VHDL code has several (many) lines with "PORT MAP" in it, followed by code
such as;

fred <= fred,
george <= george,
whatever <= whatever,
nim <= nim,

etc etc

I'd like to read down to the first instance of PORT MAP, then read all the lines with <= in them, but only up to the next PORT MAP, then find the longest string before <= and rewrite all line out with that length before the <=, so all the <= line up.
Then do it all again for every occurenc of PORT MAP to the file end.

I've donea simple one that reads the whole file and realigns, but I feel this could be done better by doing in sections.

Any help most welcome, I'm only an occasional Tcl dabbler!
.