#!/usr/bin/perl use strict; use warnings; exit unless @ARGV; my %cache = do {local @ARGV = shift @ARGV; map {($_, 1)} <>}; while (@ARGV) { local @ARGV = shift @ARGV; %cache = map {$cache{$_} ? ($_, 1) : ()} <>; } print for keys %cache; __END__