in reply to chomp - reference

Your code works for me. Try Data::Dumper to see what really is inside the $array.

Sidenote: Using both $array and @array in your code decreases its readability and makes it error prone.