in reply to Re^3: scope of my $x in if statements
in thread scope of my $x in if statements

That's only true if g() has no side-effects and no performance penalty.