my $keys = sub { my $self =shift; keys %$self }; sub f { return { a=>1, b =>2 } } print for f->$keys;