foreach my $item (@SQLvars){ my $sth = $self->dbh()->prepare($DocumentQuery) or die "Can't prepair statement: $self->DBI::errstr"; my ( $foo, $bar ); $sth->execute( $item->{PACKID}, $item->{PACKINFO} ); $sth->bind_columns(\( $foo, $bar )); while ($sth->fetch) { $XMLContent .= " $foo $bar \n"; if (){ # if there are 10 packet_ref's send the XML and loop round for the remainder my $XMLPacket; $XMLPacket = $XMLHead . $XMLContent . $XMLFoot; my $mech = WWW::Mechanize->new(); $mech->get( $TargetURL ); $mech->field( "xml_doc", $XMLPacket ); my $mechres = $mech->submit(); if ($mechres->is_success) { warn $mechres->decoded_content; return "Success"; }else{ warn $mechres->status_line, "\n"; return "Error"; } undef $XMLContent; } } }