use strict; use warnings; use Benchmark qw( cmpthese ); sub attrib_copy { my ($self) = @_; $self->{attrib} } sub attrib_nocopy { $_[0]->{attrib} } our $self = bless({ attrib => 'some_value' }); my %tests = ( copy => 'my $x = do { local @_ = $self; &main::attrib_copy };', nocopy => 'my $x = do { local @_ = $self; &main::attrib_nocopy };', inline_copy => 'my $x = do { local @_ = $self; my ($self) = @_; $self->{attrib} };', inline_nocopy => 'my $x = do { local @_ = $self; $_[0]->{attrib} };', ); $_ = 'use strict; use warnings; our $self; ' . $_ for values %tests; cmpthese(-3, \%tests);