#!/usr/bin/perl -w use strict; use Tk; my $top = MainWindow->new; my $t = $top->Text(); $t->tagConfigure("boring", -foreground => "blue"); $t->tagConfigure("special", -foreground => "red"); # Change the match rule according to taste my @words = qw(your be is silly); my $regex = join("|", @words); $regex = qr/(.*?)\b($regex)\b/s; my $text = "If you want to be immune from silly letters, don't carry your monomark in your hat.\n"; while ($text =~ /$regex/gc) { $t->insert("end", $1, "boring"); $t->insert("end", $2, "special"); } $t->insert("end", $1, "boring") if $text =~ /(.+)/gs; $t->pack; MainLoop;