Use List::Util qw( sum ); $count = sum map s/$foo/$bar/g, @array;