use Benchmark; use Inline C; timethese (1000000, { 'regex' => q{ my $foo = "test "; $foo =~ s/\s+$//; }, 'inline' => q{ my $foo = "test "; rmsp($foo); } }); __END__ __C__ void rmsp(char * str) { int i = strlen(str) - 1; while( i >= 0 && str[i] == ' ' ) { str[i--] = '\0'; } }