#!/usr/bin/perl -w use strict; my @words = ("dog good", "food fodder"); TOP: for (@words){ my ($first, $second) = split; for my $ltr (split //, $first){ unless ($second =~ s/$ltr//){ print "'$_' does not match.\n"; next TOP; } } print "'$_' matches.\n"; }