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][^w]*?[w])(.*)/ ) { my $d_len = length("$1"); $len = $d_len if( $d_len < $min ); $instr = "$2"; } print $len;