you are referencing an array inside your subroutine, but you are not actually passing it an array, you are passing it a scalar ($first). it looks as if you may have intended for @array to be a global, but then you assigned to it inside the subroutine.