my $SELECT = "SELECT * FROM mytable WHERE usercode=? AND unsubscribedby = ''"; my $UPDATE = "UPDATE mytable SET subscribed = '0', unsubscribedby = 'SYSTEM' WHERE usercode=? AND unsubscribedby = ''"; for (@usercodelist) { my $sth = $DBH->prepare($SELECT); my $q = $sth->execute($_); while (my $r = $q->fetchrow_hashref()) { print "Matched $$_{usercode}\n"; } $sth = $DBH->prepare($UPDATE); $sth->execute($_) or die "
Could not execute SQL statement ... maybe invalid?
$!
"; $sth->finish(); }