my $SQL = "UPDATE mytable SET subscribed = '0', unsubscribedby = 'SYSTEM' WHERE usercode = ? AND unsubscribedby = ''"; my $sth = $DBH->prepare( $SQL ); foreach my $md5 ( @usercodelist ) { chomp $md5; # I'm assuming a newlines is bungling your update $sth->execute( $md5 ) or die "Can't execute $SQL"; }