use strict; use warnings; use utf8; use Encode qw/encode decode decode_utf8 encode_utf8 from_to/; my $instr = decode('utf8', ); my $len = -1; my $min = 100; while($instr =~ /([c][^c]*?[w][^cw]*?[w])/g ) { my $d_len = length("$1") ; $min = $d_len if( $d_len < $min ); } if( $min == 100 ){ while($instr =~ /([c][^c]*?[w][^w]*?[w])/g ) { my $d_len = length("$1") ; $min = $d_len if( $d_len < $min ); } } print ( $min==100 ? $len : $min);