my @to_delete = $q->param('forum'); my ( @failed, @deleted ); local $dbh->{RaiseError} = 1; # so we get exceptions for errors foreach my $id (@to_delete) { eval { $dbh->do( q{ delete from mx_forums where id=? }, {}, $id ); push @successful, $id; }; push @failed, $id if $@; } # ...