#/usr/bin/perl -w use strict; my %sortOrder; # replace "file1" with the filename of the first file my $currentOrder=0; open(FILE1,") { chomp; # associate the current word with its place in the sort order $sortOrder{$_}=$currentOrder++; } close(FILE1);