sub mylength { my $string = shift; my $size = $string =~ tr///c; # Don't worry how it works. return $size; } # Invoke it like this: my $length = mylength("Hello world."); # $length now holds 12.