[\&toggleTextHighlighting \$highlight, \$regex, \$widget] #### sub toggleTextHighlighting { my ($highlight, $regex, $widget) = @_; # Deference the variables that you need to get values from $highlight = ${$highlight}; $regex = ${$regex}; $widget = ${$widget}; # Create a tag to configure the text $widget->tagConfigure('foundtag', -foreground => "white", -background => "red"); if ($highlight == 1) { $widget->FindAll(-regex, -nocase, $regex); if ($widget->tagRanges('sel')) { my %startfinish = $widget->tagRanges('sel'); foreach(sort keys %startfinish) { $widget->tagAdd("foundtag", $_, $startfinish{$_}); } $widget->tagRemove('sel', '1.0', 'end'); } } else { $widget->tagRemove("foundtag", '1.0', 'end'); } }