@words = ("print", "sprintf"); foreach my $word (@words) { my $word_len = length $word; my $next = "1.0"; while (my $from = $t->search(-regexp, "\\b$word\\b", $next, "end")) { $next = "$from + $word_len chars"; if ($_ =~ /\#/) { my @comment = split(//, $_); my $i = 0; foreach my $comment (@comment) { if ($comment eq "#") { my $offset = $i; if ($from < $offset) { $t->tagAdd("red", $from, $next); } }else{ $i++; } } }else{ $t->tagAdd("red", $from, $next); $t->tagAdd("bold", $from, $next); } } }