#!/usr/bin/perl -wl use strict; for my $f( ['the','there'], ['abcde','gcdabef'], ['abe','lbbe'], ['forky','fork'] ) { print "@$f =>", fooey($f); } sub fooey { my ($this,$that) = @{$_[0]}; my $yes; for my $char(split'',$this) { ++$yes if $that =~ /\Q$char\E/; } return $yes == length $this? 1: 0; } __END__ the there =>1 abcde gcdabef =>1 abe lbbe =>0 forky fork =>0 #### #!/usr/bin/perl -wl use strict; for my $f( ['the','there'], ['abcde','gcdabef'], ['abe','lbbe'], ['forky','fork'] ) { print "@$f =>", fooey($f); } sub fooey { my ($this,$that) = @{$_[0]}; my %yes; my $char = quotemeta $this; { $that =~ s/([$char])/$yes{$1}++/ge; } return ((scalar(keys %yes) == length $this? 1: 0); } __END__ the there =>1 abcde gcdabef =>1 abe lbbe =>0 forky fork =>0