use warnings; use strict; use Tk; my $string = "foobarbaz"; my $mw = MainWindow->new; my $regexp_entry = $mw -> Entry() -> pack; my $go_button = $mw -> Button( -takefocus => 1, -text => "Match using what you typed!", -command => sub{ my $exp = $regexp_entry -> get(); print STDOUT "I'm looking for a match for $exp...\n"; $string =~ m/$exp/ ? print STDOUT "match!\n" : print STDOUT "No match!\n"; } )-> pack; my $used_stored_exp = $mw -> Button( -text => "Match with Stored Regexp!", -command => sub{ my $exp = qr/foo/; print STDOUT "I'm looking for a match for $exp...\n"; $string =~ m/$exp/ ? print STDOUT "match!\n" : print STDOUT "No match!\n"; } )-> pack; $regexp_entry -> focus; MainLoop;