my $sum = 0; my $length = @input; # number of samples in the array @input for my $value (@input) # assuming @input are samples that have already been converted to the correct unit { my $sum += $value*value; # sum of the squares } my $dba = 10 * log10($sum/$length);