use Modern::Perl; my $sample = "A-E-H-L"; my @options = ( "A-B-C-E-H-J-L", # idx = 0 "A-B-F-G-H-K-M", # idx = 1 "A-E-G-H-L", # idx = 2 "A-C-E-G-H-J-L", # idx = 3 "B-F-H-K", # idx = 4 "A-B-F-G-H-K-L", # idx = 5 "C-H" # idx = 6 ); $sample =~ s/-/.*/g; my @matches = grep $options[$_] =~ /$sample/, 0 .. $#options; say for @matches; #### 0 2 3