in reply to pushing onto array is not working as intended..

You'd do well to use strict;use warnings. Adding those pragmas I uncover the following issues in your code:

  1. Lines 10 and 12: Your error message accesses %opt instead of %opts
  2. Line 56: By using my within the scope of an if block, you are scoping it to the block; hence, the value you assign (50) is not visible outside that block, and you'll get an undef or old data.

This of course was not your problem here, but are obviously bugs you hadn't found yet.