#!/usr/bin/perl use Benchmark qw( timethese ); $rCODE = reverse($CODE = << 'END'); int f = 1; /* comments /* used here */ if (f/1 == f) { /* you can use / here */ printf("this is /* not /* a */ comment"); } END timethese(-5, { sexeger => q{ ($last) = scalar reverse($rCODE =~ m{ ^ (?: " [^"]* " | [^*]/ | [^/"]+ )* ( /(?:\*+[^*]*[^/*])*\*+[^*]*\*/ ) (?: " [^"]* " | [^*]/ | [^/"]+ | /(?:\*+[^*]*[^/*])*\*+[^*]*\*/ )* $ }x); }, normal => q{ ($last) = $CODE =~ m{ ^ (?: " [^"]* " | /\*[^*]*\*+(?:[^/*][^*]*\*+)*/ | /[^*] | [^/"]+ )* ( /\*[^*]*\*+(?:[^/*][^*]*\*+)*/ ) (?: " [^"]* " | /[^*] | [^/"]+ )* $ }x; }}); __END__ Benchmark: running normal, sexeger, each for at least 5 CPU seconds... normal: 14 wallclock secs ( 8.99 usr + 0.00 sys = 8.99 CPU) @ 3.11/s (n=28) sexeger: 8 wallclock secs ( 5.00 usr + 0.00 sys = 5.00 CPU) @ 1078.00/s (n=5390)