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; sub chk{ my $d_len = length($_[0]) ; $min = $d_len if( $d_len < $min ); } &chk("$1") while($instr =~ /([c][^c]*?[w][^cw]*?[w])/g ); if( $min == 100 ) {&chk("$1") while($instr =~ /([c][^c]*?[w][^w]*?[w])/g )}; print ( $min==100 ? $len : $min);