my %supermatrix; my $list = "LIST.txt"; open my $DATA, '<', $list or die "unable to open my list $list $!\n"; print "\nWORKING ON $list\n"; print `head $list`; while (my $line = <$DATA>) { chomp $line; my $substrate = 1 if $line =~ /substrate.*(\d+)$/; print "SUBSTRATE ===$substrate"; $line = ; # fetch next line print "PRODUCT====$line"; my @products; (undef, @products) = split / /, $line; foreach my $prod (@products) { $supermatrix{$substrate}{$prod} = 1; print "combination $substrate $prod exists ! \n" if exists $supermatrix{$substrate}{$prod}; } }