in reply to General style advice requested
- It's a good practice to limit the scope of your variables. It looks like $first, $second and $cycle_length can be declared inside your 1st foreach loop. Similarly, $cycle_length can probably be declared in your sub.
- $number = $number / 2; can be shortened to $number /= 2;. See Assignment Operators.
- perlcritic is a tool which you can use to check for best practices. I ran it on your code, but nothing significant (in my opinion) was reported.