in reply to How to process with huge data's
I don't see major faults in your script, but that much data should easily be calculated within a few minutes, if not seconds. However, here are a few problems.
Drop the $inputtext = $_ assignment, and change your top-level regexps to have an anchor in the beginning:
if (m/^q (\d+) (\d+)/)
Second, the m/\b$fnum\b[^\|]*\b$snum\b/ regexps are forcing the regexp engine to recompile that on almost every run (as the variables change). This is highly inefficient -- the whole if/elsif/else chain should be parsed differently. I'm not sure what the purpose of that block is, but at the very least you can change some of $fnum/$snum into \d+