my @words = ; #### #! /usr/bin/perl -w use strict; my $input = 'art'; # Read words from a file instead. my @words = ('tar', 'rat', 'fake', 'at', 'unknown'); my $regex = qr{[$input]+}; my @matches = grep /^$regex$/, @words; print "$_\n" for @matches;