# filename format: filename-timestamp-counter.txt # assumption: $ts contains timestamp in unix time format # (seconds since epoch) # assumption: $filename created earlier with 'my', # and will contain the filename at end my @fnp = ('file', $ts, 0); $fnp[2]++ while (-e join('-', @fnp)); $filename = join('-', @fnp) . '.txt';