I will try the use strict and use warning. But as far as the $sof_to_delete, it is incrementing at each iteration of the for (@sof_i) statement, but that for (@sof_i) statement has a last if $_=~/^={30}/; statement which should stop the for statement after about 5 lines. (every 5 lines is a line of =========== .
so then the sub would be called multiple times and the ^={30}, is just tellin it to stop for now right? btw, simple print debugging can be very revealing. checking the value interactively as you go through the code. something like
print $var_to_check;
my $dummy = <STDIN>; #so it doesn' fly by in programs that generate lo
+ts of output