my @strings = qw( 1234579 234789 4578 ); my %c = map { $_ => 1 } split //, shift @strings; %c = map { $_ => 1 } grep { $c{$_} } split // for @strings; print keys %c, "\n";