stop_reference | service_id | distance ----------------+------------+------------------ 6200200581 | 1 | 131 6200249240 | 2 | 148.32734070292 6200249230 | 2 | 247.695377429616 6200249250 | 2 | 394.507287638644 6200249220 | 2 | 394.81641303269 #### $originsql = qq{ SELECT a.stop_reference, b.service_id, distance....}; $sth = $dbh->prepare( $originsql ); $sth->execute(); $sth->bind_columns( undef, \$stops, \$service, \$distance ); while( $sth->fetch() ) {