if ( defined $operator and $operator =~ /\S/ ) { #print operator here #it is defined and contains something #that is not whitespace } else { #do something else as $operator is either #not defined or it does not contain a #non whitespace character }