#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11163777 use warnings; my @wanted = (1, 2, 3, 4); my $pattern = join '', map "(?=.*\Q$_\E)", @wanted; for my $test ('1432', '1345', 'brown fox', '9876?54321') { printf "%20s => %s\n", $test, $test =~ /^$pattern/s ? "has all" : "does not have all"; } #### 1432 => has all 1345 => does not have all brown fox => does not have all 9876?54321 => has all