use feature 'signatures'; my $on = 0; sub switch_lamps ($switch_to) { state $lamp_state = 0; return if $lamp_state == $switch_to; $lamp_state = $switch_to; # ... } sub is_nighttime { #... } while (1) { switch_lamps( $on && is_nighttime() ); sleep(60); }