# choose an appropriate separator char, I like to use ':' # using concat() gives us a single column result for a two # (or more) column need my $sql_select = "select distinct concat(LiftChr, ':', LiftPos) from $tableName"; # since we're requesting a single final column, we can use # the selectcol_arrayref() to get all values at once my $array_ref = $db->selectcol_arrayref($sql_select); # or die? check for errors! # now we have all keys and we're not in an active statement either my $sql_delete = "delete from $tableName where LiftChr=? and LiftPos=?"; my $sth1 = $db->prepare($sql_delete); # this loop steps through a simple array # waaay faster than fetching row by row foreach (@$array_ref) { # separate the 'single' column back into it's parts my ($chr, $pos) = split(/:/, $_); # profit $sth1->execute($chr, $pos); }