my( $name, $ascii ); foreach ( qw/ONE TWO THREE FOUR/ ) { $name = ucfirst lc; $ascii = $name; $ascii =~ s/(.)/ord $1/ge; print $ascii; last if $ascii =~ /\d{6,}/; } undef $name; undef $ascii; # or foreach ( qw/ONE TWO THREE FOUR/ ) { my $name = ucfirst lc; my $ascii = $name; $ascii =~ s/(.)/ord $1/ge; print $ascii; last if $ascii =~ /\d{6,}/; } #### Benchmark: timing 100000 iterations of InLoop, OutLoop... InLoop: 4 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 30959.75/s (n=100000) OutLoop: 3 wallclock secs ( 3.59 usr + 0.00 sys = 3.59 CPU) @ 27855.15/s (n=100000) Benchmark: timing 1000000 iterations of InLoop, OutLoop... InLoop: 38 wallclock secs (32.36 usr + 0.00 sys = 32.36 CPU) @ 30902.35/s (n=1000000) OutLoop: 40 wallclock secs (34.82 usr + 0.00 sys = 34.82 CPU) @ 28719.13/s (n=1000000) Benchmark: timing 10000000 iterations of InLoop, OutLoop... InLoop: 372 wallclock secs (322.27 usr + 0.09 sys = 322.36 CPU) @ 31021.22/s (n=10000000) OutLoop: 411 wallclock secs (347.93 usr + 0.23 sys = 348.16 CPU) @ 28722.43/s (n=10000000)