use strict; use warnings; use Tk; my %w; $w{mw} = MainWindow->new; $w{topfr} = $w{mw}->Frame()->pack( -expand => 1, -fill => 'x' ); $w{textfr} = $w{mw}->Frame()->pack( -expand => 1, -fill => 'both' ); $w{topfr}->Button( -text => 'Previous', -command => sub { nextText('-backwards') } )->pack( -side => 'left' ); $w{searchstring} = $w{topfr}->Entry( -text => 'text', )->pack( -side => 'left' ); $w{topfr}->Button( -text => 'Next', -command => sub { nextText('-forwards') } )->pack( -side => 'left' ); $w{textWindow} = $w{textfr}->Scrolled( 'Text', -scrollbars => 'ose' ) ->pack( -expand => 1, -fill => 'both' ); $w{textWindow}->insert( 'end', q|I have a Scrolled Text widget in my application. I am trying to implement an incremental search of a string on this text widget. I have come up with the following logic , but it only highlights the first occurence and not the remaining ocuurences. Please help me to make it incremental for the entire text widget. Following is my code | ); $w{textWindow}->focus; MainLoop; sub nextText { my $direction = shift; my $string = $w{searchstring}->get; $w{textWindow}->FindNext( $direction, '-exact', '-nocase', $string ); }