use Variable::Magic qw( wizard cast ); my $wiz = wizard( set => sub { print "Now set to ${$_[0]}.\n" }, ); cast my $name, $wiz;