use strict; use warnings; use Data::Dumper; my $word='perlmonks'; my %wordCharCount; my @matches; my $input; my %chars; my $boolean=1; my $k; map {$wordCharCount{$_}++} (split(//,$word)); while (<>) { $input = $_; if (/^[$word]*$/) { #print "candidate: $_"; @matches = ($input =~ m/ (.{1}?) (?{ $chars{$^N}++; }) /xg); foreach $k (keys %chars) { $boolean = ($wordCharCount{$k} >= $chars{$k}?1:0) && $boolean; # print "$wordCharCount{$k} <=> $chars{$k} yields $boolean\n"; } print if $boolean; #print "hit: $_" if $boolean; undef %chars; $boolean=1; } }