use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $entry1 = $mw->Entry()->pack(); my $entry2 = $mw->Entry()->pack(); my $entry3 = $mw->Entry()->pack(); my %after = ($entry1 => $entry2, $entry2 => $entry1, ); $mw -> bind('all','',sub{ ($after{$_[0]})->focus; } ); $mw->MainLoop(); exit(0); #### Tk::Error: Can't call method "focus" on an undefined value at C:\Users\FC\Desktop\Entry.pl line 14. (command bound to event)