{ package Undef; sub TIESCALAR{ bless \pop, 'Undef';} sub STORE{ $$_[0] = $_[1]; } sub FETCH{ defined $$_[0] ? $$_[0] : 0 } }; tie $x, 'Undef'; $x = 0; print "'$x'"; '0' $x = ''; print "'$x'"; '' $x = undef; print "'$x'"; '0'