#!/usr/bin/perl use strict; use warnings; my %all = map{$_, $_} do{local @ARGV = shift; <>}; %all = map{$_, $_} grep defined, @all{do{local @ARGV = $_; <>}} for @ARGV; print sort keys %all; #### ID121 ABC14 ID122 EFG87 ID157 TSR11