use DB_File; my $hash; tie %hash, DB_File, "first_file.hash"; while () { $hash{$_} = undef; } while () { print $_ if exists $hash{$_}; } #### my $h = 0; foreach (split("", $line)) { $h+=ord($_) } $h = $h % 256; #### file1/0 file1/1 ... file1/255 file2/0 file2/1 ... file2/255