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,}/; }