in reply to looping safely

You should post an SSCCE instead of vague excerpts of what you think are the relevant parts of your program.

In the problematic part of your program, you show:

while ($STPU eq 'good') {

So, when does $STPU ever get to ne 'good' ? Think about this.

For your "slow" script, consider to do the database updates for more than one row maybe?

Without seeing what takes the time, it's really hard to tell what goes wrong.

My approach given the bad information you gave would be to loop up to 10 times in the "bad" program:

my $count = 0; while ($STPU eq 'good' and $count++ < 10 ) { ... }

This does a maximum of 10 changes.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.