# generate a closure: sub gen_change_mode { my $mode = shift; return { # same code as in change_mode }; } # then do this $main->Button(-text => 'To Upper Case', -command => gen_change_mode(2) )->pack; # or this $some_ref = gen_change_mode(3); $main->Button(-text => 'To Mixed Case', -command => $some_ref )->pack;