my @ifaces; my @hosts; while ( my @row = $sth->fetchrow_array ) { my $host = $row[0]; my $iface = $row[1]; my $type = $row[2]; my $address = $row[3]; my $netmask = $row[4]; my $gateway = $row[5]; push( @hosts, "$host" ); ########### Here's what I can't get right ############# while ( @hosts ) { push( @ifaces, "$iface"); @ifaces = pop( @ifaces ); last; } ########### Above is what I can't get right ############# my $tmp_file = "/tmp/interfaces.$host"; my $loopback_string = "auto lo\niface lo inet loopback\n\nauto"; open(my $interfaces_file,"+>>$tmp_file") or die "Unable to open $tmp_file: $!\n"; if ( -z $tmp_file ) { print {$interfaces_file} "$loopback_string @ifaces\n\n"; } if ($type eq "dhcp") { print {$interfaces_file} "iface $iface inet $type\n\n"; } else { print {$interfaces_file} "iface $iface inet $type\naddress $address\nnetmask $netmask\nnetwork 192.168.0.0\nbroadcast 192.168.0.255\ngateway $gateway\n"; close($interfaces_file) or die "Can't close it\n"; } } $dbh->disconnect;