There could be more than one word matched, so try this:
#! perl
use strict;
use warnings;
use String::Approx qw(amatch);
my @list = qw(Apple Pear Orange);
my @inputs = qw(aple appe peay range oranges mango appple aqqple);
for my $word (@inputs)
{
my @matches = amatch($word, ['i'], @list);
if (@matches)
{
print "Matched: $word to: ", join(', ', @matches), "\n";
}
else
{
print "Unmatched: $word\n";
}
}
Output:
22:27 >perl 1501_SoPW.pl
Matched: aple to: Apple
Matched: appe to: Apple
Matched: peay to: Pear
Matched: range to: Orange
Matched: oranges to: Orange
Unmatched: mango
Matched: appple to: Apple
Unmatched: aqqple
22:27 >
Hope that helps,