my %prefs; ... eval { my $sth=$dbh->prepare("SELECT prefname, prefvalue FROM prefs WHERE user_login=?"; $sth->execute($login); $sth->bind_columns( \my( $n, $v ) ); while($sth->fetch) { $prefs{$n}=$v; } }; if($@) { #as before } #later to use print "My favorite color is $prefs{color1}\n"; # or even foreach my $p ( keys %prefs ) { print "I like my $p to be $prefs{$p}\n": }