#!/usr/bin/perl # create names lookup table from first file while (<>) { #get rid of newline in name because there might be #something like >name1\stext\n in the second file chomp; $names{$_} = 1; last if eof; } $/ = "\n>"; # set input record separator # scan second file print ">"; # print first ">" that would be missing while (<>) { print if /^>?([\w\d]+)/ && $names{$1}; }