Your sql queries are single pass operations. If you want to loop over the second collection more than once, you need to either cache the values and interate over the cache, or rerun the query.
I would of course advise that you go with the first option using fetchall_arrayref
my $wan_arrayref = $wan_collection->fetchall_arrayref;
while ( my @ip_core_wan_field = $wan_core_collection->fetchrow_array() ) {
my $coreipAddr = @ip_core_wan_field[1];
for my $ip_wan_field_ref (@$wan_arrayref) {
my @ip_wan_field = @$ip_wan_field_ref;
There are of course other ways to make this operation more efficient, but that's the crux of your current problem.