use DB_File; my $hash; tie %hash, DB_File, "first_file.hash"; while () { $hash{$_} = undef; } while () { print $_ if exists $hash{$_}; }