... use List::MoreUtils qw(uniq); open($fh, '<', 'filetoparse.txt') or die "error $!"; chomp(my @lines = <$fh>); close $fh; my @old_ids; foreach my $line (@lines) { @data = split(/\t/, $line); push @old_ids, $data[12]; } my @uniq_ids = uniq (@old_ids); #get unique ids #step through unique ids for new id using old ids for my $i (0..$#uniq_ids) { print $uniq_ids[$i] * 1; #line 78 of my code to test for a number my $stmt = "SELECT * FROM temp_topics WHERE old_id = ?"; my $topic = $dbh->selectrow_hashref($stmt, undef, $uniq_id[$i]); etc. }