in reply to Strange undefined scalars in array

I think the core problem here, is you misunderstand what 'my' and 'our' does.

'my' creates a new variable, valid within the current scope, and as a new variable - it's undefined.

'our' is used to import variables from other packages. You probably don't want to use it.

Perldoc on 'our'

Perldoc on 'my'

Normally, 'my' is what you'll want to use, but when using it in a loop, if it's _inside_ the loop, you'll get a new variable each iteration.

So:

while (my $modelselect ne '10')

Is creating a new '$modelselect' each time you run that loop, which is almost certainly not what you want to do, because that way your loop says:

while (undef ne '10')

Likewise:

push (@switches, my $portcount);

Is doing the same thing. $portcount is being defined right there (and if you'd already declared it, would spit out an error) - you do actually have two separate 'my $portcounts' but they're in different subroutines, which means they're completely separate instances of the same variable.