\@bex won't work unless you do my @bex in the foreach loop. You mentioned this (in less explicit terms), but I just wanted to be clear. Without the my, all values will be references to the same array. In fact, the OP says he's using [@bex], but the symptoms he's describing are those of \@bex.