in reply to How scoping works in If statements?

just my 2 cents and thoughts:

If you had enabled warnings, you should have seen this warning:

"my" variable $x masks earlier declaration in same scope at - line ...

The two ways aren't equal because the first uses the "my $x = 5;" inside a block, so it has its own scope (the block); the second one is done without the block and is executed in the same scope as the "my $x = 10;" which causes that the warning is generated (if warnings are enabled).

The scoping is done by the {} not by the if.