#!/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;