use strict; use warnings; my ($file1, $file2) = @ARGV; my $maxL = 40; # max name length my $ids = 10000000; # last id my $bin="\0" x ($maxL * $ids) ; # Create the index open my $fh1, "<", $file1 or die $!; while (<$fh1>){ chomp; my ($id,$name) = split /\s+/; substr($bin, $id*$maxL, $maxL, pack ("A$maxL",$name)); } close $fh1; # Search $ids from file 2 open my $fh2, "<", $file2 or die $!; while (<$fh2>){ chomp; my $binval = substr ($bin,$_*$maxL,$maxL); my $valback = unpack ("A$maxL",$binval); print "$_ => $valback\n"; } close $fh2;