my @a = ( 'a', 'x', 'z' ); my $match = qr/^[@{[ join '', @a ]}]{3}$/; while(<>) { print if /$match/; }