use strict; use warnings; my %strings = ( 'undef' => undef, 'empty' => '', 'string' => '0' ); my @pairs = ( [ 'undef' , 'undef' ], [ 'undef' , 'empty' ], [ 'undef' , 'string' ], [ 'empty' , 'empty' ], [ 'empty' , 'string' ], [ 'string', 'string' ], ); for ( @pairs ) { my ($p,$q) = @strings{@$_}; my $cmp = ( (defined($p) ? '1' . $p : 0) eq (defined($q) ? '1' . $q : 0) ) ? 'true' : 'false'; print join(" eq ", @$_), " = $cmp\n"; }