use warnings; use strict; my (@results, @final, %seen); while(<>){ tr/\0//d; # strip NULs # if we're INSERTing into Photo (but not from)... if (/(?[1] cmp $b->[1] } @results; open OUT, ">results.txt" or die $!; for my $line (@final) { my $fieldNames = $line->[1]; # if we've never seen these values, print if (not $seen{$fieldNames}) { print OUT @$line; $seen{$fieldName}++; } } close OUT; #### # split BEFORE a ( or AFTER a ) my @s = split /(?=\()|(?<=\))/; push @results, \@s; ### that even lets you get away with leaving out @s push @results, [ split /(?=\()|(?<=\))/ ]; #### # display the line if we've never seen the fields print OUT @$line if not $seen{$line->[1]}++;