use strict; use warnings; my ($c, %h, $key); my @file1 = ( "A B C D E F G\n", "A C B D E F G\n", "D B C A E F G\n", "B B C D E F G\n" ); for (@file1) { $h{join ' ',(split / /)[0..3]} = $c++; } while () { $key = join ' ',(split / /)[0..3]; if (exists $h{$key}) { print if $_ ne $file1[$h{$key}]; } } __DATA__ A B C D E F G A C B D E F H D B C A I F G B B C D E F G