Invoke tagConfigure with the -state parameter, with a value 'hidden'. When this tag is added to a range, the text will not be displayed in the text widget. Invoking tagRemove with the tag name and range will make the text visible again.
# A quick demo: hide the selected text,
# press the Escape key to make hidden
# text visible again
$mw = tkinit;
$t = $mw->Text->pack;
$t->tagConfigure(
'hide',
-state => 'hidden',
);
$b = $mw->Button(
-text => 'Hide',
-command => \&hide_text,
)->pack;
$mw->bind('<Escape>', \&show_text);
MainLoop;
sub show_text {
my @r = $t->tagRanges('hide');
return unless @r;
$t->tagRemove('hide', @r);
return;
}
sub hide_text {
my @r = $t->tagRanges('sel');
return unless @r;
$t->tagAdd('hide',@r);
return;
}