Exactly. Looping over the file content the value of $_ is modified, which modifies the elements of @floors. The last value is
undef (read at each file's end), so @floors ends up containing undefs after going through building1. Try adding the following line after the beginning of the
foreach (@floors) loop:
warn "FLOORS: @floors.\n";