use strict; use warnings; my $str = <>; chomp $str; my %p = (m => length($str)+1, c => scalar(() = $str =~ m/o/g)); for my $i(split '', $str){ print sprintf("%.13f", $p{c}/--$p{m} * 100)."\n"; if($i eq 'o' and $p{c}){ $p{c}--; } }