http://qs321.pair.com?node_id=483853


in reply to Capturing occurrence counts via tr/// with variable interpolation

Use $ans = @{[ $str =~ m/$SrchStr/g ]}; and forget about using eval.

Your $SrchStr, say, if want to find occurances of 'a' and 'z', should be "[az]".

Replies are listed 'Best First'.
Re^2: Capturing occurrence counts via tr/// with variable interpolation
by Roy Johnson (Monsignor) on Aug 15, 2005 at 14:03 UTC
    The other idiom for getting the count from m// is
    $ans = () = $str =~ m/$SrchStr/g;

    Caution: Contents may have been coded under pressure.