my $query = $dbh->prepare("SELECT * FROM Sector, Lane_has_Sector WHERE Sector_idSector = idSector AND Lane_wid = ? ORDER BY metric"); $query->execute($wid); while (my $sec = $query->fetchrow_hashref) { # More stuff happens here... ($sec->{'authority'}, my $prefix, my $suffix) = $dbh->selectrow_array("SELECT name, prefix, suffix FROM Authority WHERE idAuthority = ?", undef, $sec->{'Authority_idAuthority'}); $prefix = "$prefix " if $prefix; $suffix = " $suffix" if $suffix; push @authority, $prefix . $sec->{'authority'} . $suffix unless $prefix . $sec->{'authority'} . $suffix ~~ @authority; } my $auth_list = join '
', @authority;