# Rarely, you should replace: sub foo { # ... my $bar= init() if condition(); # ... } # With: BEGIN { my $prevBar; sub foo { # ... my $bar= $prevBar; $prevBar= $bar= init() if condition(); # ... } } #### # Usually, you should replace: my $bar= init() if condition(); # With: my $bar; $bar= init() if condition(); # or even: my $bar= condition() ? init() : undef;