use strict; use warnings; use 5.012; use Tk; my $entry_text; my $mw = MainWindow->new; my $entry = $mw->Entry( -text => 'Enter answer here', )->pack; $entry->focus; $entry->selectionRange(0, 'end'); sub my_validator { my $input = $entry->get(); if ($input eq 'hello') { $entry->delete(0, 'end'); $entry->insert(0, 'Try again!'); $entry->selectionRange(0, 'end'); $entry->icursor(0); } else { say "Thanks for the great input!"; $entry_text = $input; say $entry_text; } } $mw->Button( -text => 'Submit', -command => \&my_validator, )->pack; MainLoop;