my $name = undef; # store subparent for each parent my %parent_hash = ( 'Father' => 'Mother', 'Mother' => 'Father' ); if (exists $parent_hash{$parent}) { my $sub_parent = $parent_hash{$parent}; for my $col ( $parent, $sub_parent ) { my $sql = "select $col from Roster where User=?"; my $rv = $dbh->selectcol_arrayref( $sql, undef, $user ); if ( @$rv ) { # any rows returned? $name = $rv->[0]; # take first one last; } } } # here, $name will be defined if one of above succeeded