albeit untested
Indeed ;-) A couple of things go wrong. @infiles is not initialised, but I guess this is left as an exercise to the OP. No, I really wanted to point out the use of exit, which is not what you want here, IIUC. exit terminates the program however deep you are in nested blocs. By using exit here, you stop the program once the first file has been renamed with a suffix. Instead of that, you want to proceed to the next file.
But
next goes to the next iteration of the innermost loop. In our case, that would be the loop on suffices, not on files. So you'll need to use LABELS:
FILE: foreach my $filename (@infiles) {
...
if ( -e $ofilename ) {
SUFFIX: for (@suffix) {
if ( ! -e "$ofilename.$_" ) {
...
next FILE;
} else {
...
}
}
} else {
...
}
}
--bwana147