- I missed the significance of the $fac value. my bad!
- You told us you "start with" the $fac values. Now you show that's not the case. Your bad!
- Since you are calculating that, you have all the data points needed to solve your alignment problem.
- chop does NOT do what you appear to think it does. See the docs for chop and chomp, the latter of which more reliably removes a trailing newline (as opposed to discards the final entity on a line).
- The regex matches in your initial test, above, if ($_ =~/(.*)/) {...}? matches anything or nothing (ie, is useless or 'ALWAYS true-for-any-non-blank-line'): the dot means any character (alpha, digit, punct, or whitespace (except \n and the * quantifier means "none" or "any-quant-more-than-none" (see perlre).
- Var names such as $f, $s may be 'meaningful' to you, today... but they're apt to give grief, agitta and annoyance to some future you - or to the homicidal maniac who knows where you live and who may have to take over maintenance someday. Name vars with names or obvious and unambiguous abbreviations. They'll save you g,a and a.
So, bottom line, I'm not giving you the code to solve your alignment problem; you'll learn more by solving that yourself, with the info you now have in hand, than by getting an algorithm spelled out or by copying code. But before you tackle that one, read the cited regex doc, and probably the tuts here. (Yes, they're directly relevant to one approach.)