use strict; # Put all of the $usefuldata stuff in a subroutine sub get_useful_data { # Eliminated initial assignment of $usefuldata... # There's no need to calculate it if blah_blah() # is true and we're going to replace the value anyway if ( blah_blah() ) { # No need to store $usefuldata in a variable... # just return it return 2; } else { # Since blah_blah() is false, we return the default # case return 1; } } # Now we can calculate $usefuldata exactly where we want it insert_into_database( get_useful_data() )