$sample = "A-E-H-L"; @options = ( "A-B-F-G-H-K-M", # idx = 0 "A-E-G-H-L", # idx = 1 "A-C-E-G-H-J-L", # idx = 2 "B-F-H-K", # idx = 3 "A-B-F-G-H-K-L", # idx = 4 "C-H" # idx = 5 ); $mc = "[A,E,H,L]"; @matches = grep(/$mc/, @options); foreach $x (@matches) { printf("> %s\n", $x); }