in reply to what happens when lexical variables go out of scope?

In your case, $ftp is the only reference to the Net::FTP object. $ftp goes out of scope at the end of the block, so the object gets DESTROYed at that point.

For code like this:

{ my $connection; { my $ftp = Net::FTP->new('some.host'); $connection->{ftp} = $ftp; } #1 # Do stuff with $connection->{ftp}... } #2
$ftp goes out of scope at #1, but there's still a reference being held (in $connection->{ftp}!), so the Net::FTP only gets destroyed at #2.

Think of a "reference" as an arrow pointing to a thingy. It goes from an lvalue (something that's assignable, like a scalar variable or a slot in an array or in a hash) to a thingy. The thingy knows how many arrows point at it; it goes away when the last arrow goes away.