in reply to
Re^2: incrementing the file
in thread incrementing the file
You can try starting with a "templated" filename and increment it until you get past all the existing files:
my $fn = "output000";
$fn++ while -e $fn;
At that point, you'll have a filename that is just past the last one of that pattern. Minor caveat: make sure you have enough zeroes at the end of the template - or you'll start incrementing the characters. Yes, really.
ben@feynman:~$ perl -wle'$number = "one"; $number++ for 1..3624; print
I hate storms, but calms undermine my spirits.
-- Bernard Moitessier, "The Long Way"