$ perl -le' my $target = "PEARLYGATES"; my $word = "EASYPEASY"; ( my $temp = $target ) =~ s/[^$word]//g; print join( "", sort split //, $temp ) eq join( "", sort split //, $word ) ? "Match" : "No match"; ' No match