use strict; use warnings; my %hash = ( A => 'a', B => 'b', C => 'c', D => 'd', E => 'e', F => 'f' ); print "@{[%hash]}"; while(my ($key, $value) = each(%hash)) { $hash{$key} = '= '.$value.' AND'; } my $query = 'SELECT row_id FROM Table WHERE '.substr("@{[%hash]}",0,-4); print "\n\n$query\n";