# Prepare your statement at the start of your program my $ST = $DB->prepare(q{ REPLACE INTO met_office_raw_data SET observation_datetime_utc = ?, observation_datetime_local = ?, observation_datetime = ?, station_id = ?, station_name = ?, temp_c = ?, dewpoint_c = ?, humidity_rh = ?, wind_dir_compass = ?, wind_speed_mph = ?, wind_gust_mph = ?, visibility_metres = ?, pressure_hpa = ?, pressure_tendency = ?, weather_type = ? }); while (....) { # Then for each reading, get the values my ( $file_obs_datetime_utc, $file_obs_datetime_local, $file_obs_datetime, $file_station_id, $file_station_name, $file_temp_c, $file_dewpoint_c, $file_humidity_rh, $file_wind_dir_compass, $file_wind_speed_mph, $file_wind_gust_mph, $file_visibility_metres, $file_pressure_hpa, $file_pressure_tendency, $file_weather_type ) = get_my_data(); # and write them to the table $ST->execute( $file_obs_datetime_utc, $file_obs_datetime_local, $file_obs_datetime, $file_station_id, $file_station_name, $file_temp_c, $file_dewpoint_c, $file_humidity_rh, $file_wind_dir_compass, $file_wind_speed_mph, $file_wind_gust_mph, $file_visibility_metres, $file_pressure_hpa, $file_pressure_tendency, $file_weather_type ); } #### while (....) { # Then for each reading, get the values my @data_fields = get_my_data(); # and write them to the table $ST->execute(@data_fields); }