my $Val=""; while ( my $dat_ref = $sth2->fetchrow_hashref("NAME_lc") ) { foreach my $val(@eachCols) { $Val = $dat_ref->{$val}; } }