#!/usr/bin/perl -w use strict; use warnings; my @data_list = ( {key => 'date', value => '2009-01-01'}, {key => 'correct', value => 'some_data_here'}, {key => 'date', value => '2009-01-02'}, {key => 'correct', value => 'some_data_here_again'} ); # Presumption of your test data based on your code.. my ($cor, $date); foreach my $data_pair(@data_list) { $cor = $data_pair->{value} if($data_pair->{key} eq 'correct'); $date = $data_pair->{value} if($data_pair->{key} eq 'date'); if($cor && $date) { # SQL Update goes here.... print "Found a match for $date and $cor\n"; # Reset for the next loop ($cor, $date) = (undef, undef); } }