http://www.perlmonks.org?node_id=1003747


in reply to Need help to fine tune perl script to make it faster( currently taking more than 30 minutes)

Others have given you most of the answer, but it also looks as though you're pulling the record number out by some incredibly convoluted process. What is wrong with something like:
/Record(\d+):/ && do { $recnum = $1; s/$str1/$str2/g; s/$str3/$str4/g; .. }
This checks for matching lines and pulls the record number out at the same time...

Note that the regex in the above may not be quite right as your original seems to back up 6 characters from the ':', but the regex can be amended to do that too.

A Monk aims to give answers to those who have none, and to learn from those who know more.
  • Comment on Re: Need help to fine tune perl script to make it faster( currently taking more than 30 minutes)
  • Download Code