actual script (in module one): $self->_connectdb(connection => "./db/db/db.db"); open (NROUT, ">", "./bin/PhyloStr/tmp/NROUTtmp") || die "$! \n"; $self->_doit(statement => 'begin'); $self->_fetchrow_stmt(table => 'TABE'); while (my $row = $self->_return_row()){ print NROUT ">G$row->[0]T$row->[1]\n$row->[2]\n";; } $self->_finish_stmt(); close NROUT; $self->_disconnectdb(); ######################### sub in a module two: my $fetchrow_stmt; sub _fetchrow_stmt { my ($self,%arg) = @_; my $stm = "select * from $arg{table}"; $fetchrow_stmt = $dbh->prepare($stm) || die $dbh->errstr; ; $fetchrow_stmt->execute || die $dbh->errstr; } sub _return_row { my ($self,%arg) =@_; return $fetchrow_stmt->fetchrow_arrayref(); } sub _finish_stmt { my ($self,%arg) = @_; $fetchrow_stmt->finish() || die $dbh->errstr; undef($fetchrow_stmt); }