in reply to if var isnt used

If you want to check if it matched a 0-length string, try
if (length($a))

Altogether, it can be written as:
$a = 1 if not length $a;
or
$a = 1 if length $a != 0;

By the way, you shouldn't use $a and $b as variables. They mean something special to sort.