in reply to Empty table row

Try something like
@arr=$sth->fetchrow or do { print ''; return; }
That way, if the fetch from the database returns an empty array, you do the alternative.

But, why are you rolling your own template system? Decent template systems will will handle this type of display logic much more cleanly:

use strict; use HTML::Template; sub registerform { my $templ = HTML::Template->new(filename => $register_template); my $sql = <<EOSQL; SELECT usr.name, sl.sdsc1, sl.surl1, sl.header, sl.sdsc2, sl.surl2, sl.sdsc3, sl.surl3, sl.sdsc4, sl.surl4, sl.sdsc5, sl.surl5, sl.sdsc6, sl.surl6, sl.sdsc7, sl.surl7, sl.sdsc8, sl.surl8, sl.sdsc9, sl.surl9, sl.sdsc10, sl.surl10, sl.sdsc11, sl.surl11 FROM users usr, sitelinks sl WHERE usr.userid='$refer' AND sl.userid='$refer' AND sl.status=1 EOSQL my $sth = $dbh->prepare($sql); $sth->execute; my $row = $sth->fetchrow_hashref; $templ->param($row); print $templ->output; }
Decent template systems will have if-then-else constructs to implement display logic like what you're trying to implement.

Take a look at HTML::Template or Template Toolkit.