##
my $dbconnection = DBI->connect("dbi:Pg:dbname=$database", $dbuser, $usrpsswd);
####
my $query = $dbconnection->prepare(<##
$query->execute();
####
while (($something1,$something2) = $query->fetchrow_array() ) {
do your stuff here
}
# and then disconnect
$dbconnection->disconnect();