sub get_all_data{ return $sth2->fetchall_arrayref(); } $p = Project->new_project($id); $cursor = $p->get_all_data(); $| = 1; # to turn on autoflush (turn off print/output cashing) foreach my $row (@$cursor){ print OUTPUT do{ local $" = qq{\t}; qq{$row->[1]\$\$\$\$\n}; } if defined $row->[1]; }