in reply to If condition

I can only presume you are waiting for both 'date' and 'correct' to be true before inserting into the DB.

I would agree with earlier comments about your SQL, and ask why you are creating it in a variable and not inserting it? much better to add placeholders...

Presuming you are doing what I think you are, and are waiting for both the date and 'correct' to be true this may help

#!/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); } }