I read your question different from my esteemed fellow monks. I think you don't want to just substract the start and end time from your script. I think you want to do two independent things:
- calculate the time it takes to finish your script, while the script is running.
- show that time and the current progress to the user in a CGI context
Regarding the latter you should read
CGI progress indicator which contains more links to more resources for this problem.
To solve the first you must be aware how the problem can be split in "units" (lines of csv-file*, records of a fixed-length file/database query or one solution in a shuffle of n numbers, etc.) and how many "units" there are. If that number is undetermina(te|ble) or the processing time per "unit" varies widely, it's hard to predict the runtime reliably.
The main algorithm is relatively simple:
remember starttime
determine total_number_of_units
loop as long there is a unit to process
process unit
calculate elapsed time
calculate average of elapsed time per unit
multiply average with total number of units #this gets the predicted
+ runtime
end loop
I leave it to you to translate that to Perl, since you gave us no code to work with.
Update:
* In the case of a CSV file the number of lines is usually unknown, so it makes sense to use a Byte as a "unit" and to sum up the bytes read to calculate the average.