use strict; use warnings; sub test { my ($str1,$str2) = @_; my %h; $h{$_}++ for split //, $str1; $h{$_}-- for split //, $str2; $_ and return 0 for values %h; return 1; } print test(("Hello World!")x2); # 1 print test("Hello World!","Hello World"); # 0