Issue
I have an array of substring
@substringarray = ('12347', '12357', '123467', '123488')
Then I have a value of a full string to find out
$fullstring = '123477777777';
How can I use it to find the match with It should return 12347
I want something like this:
@testsa = grep( /^$fullstring/, @substringarray);
Solution
A short way, TMTOWTDI:
#!/usr/bin/env perl
use strict; use warnings;
my @substringarray = ('12347', '12357', '123467', '123488');
my $fullstring = '123477777777';
print for grep { $fullstring =~ m/^$_/ } @substringarray;
Output
12347
Answered By - Gilles Quénot Answer Checked By - Marilyn (WPSolving Volunteer)