I32 lvalue = PL_op->op_flags & OPf_MOD || LVRET; #### sub foo :lvalue { LVALUE { ... } RVALUE { ... } } #### use Variable::Magic qw( wizard cast ); { my $wiz = wizard( # Called before reading the magic scalar (${$_[0]}). # Assign the value to ${$_[0]} that you want to be fetched. # $data is $_[1]. get => sub { ... }, # Called after an assignment to the magic scalar (${$_[0]}). # $data is $_[1]. set => sub { ... }, ); sub foo :lvalue { LVALUE { my $data = ...; cast(my $magical, $wiz, $data); $magical } RVALUE { ... } } }