in reply to scoping question

You're getting the error because all the if and elsif expressions execute in the same scope (which starts with the if and ends with the last 'then', elsif or else clause). You just need to remove the second my since the first one is still in effect.

if ( my $id = $obj->get_id() ) { $obj->do_this(); } elsif ( $id = $obj->create_id() ) { $obj->do_that(); } else { $obj->do_somethingelse(); }

However, I find the lack of symetry in the above code weird. I would probably do as you did and place a my $id; outside of the if. You can add curlies around the my and the if if you wish to tighten the scope.