That's what test2.tcl in this [L1 ] "Regular Expressions" [L2 ] column does.
Also see the fileevent page.
The sample chapter 22 from Brent Welchs book can be downloaded from his home page and ( "TK Examples", or "TK by Example" ) [L3 ] also gives an example of this.