That's what test2.tcl in this [L1 ] "Regular Expressions" [L2 ] column does.
Also see the fileevent page.
The sample chapter 22 ( "TK Examples", or "TK by Example" ) [L3 ] also gives an example of this.
Category GUI