my @word = split //, $word_to_match; my $match = 0; for (0 .. $#word) { $match = 1 && last if $word_to_compare eq join //, @word[0..$_]; } print "Matched!\n" if $match;