my $str1 = "olleh"; my $str2 = "elloh"; if ( $str1 =~ /\A[$str2]+\z/ ) { print "$str1 and $str2 contain the same characters.\n"; }