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") ; if( $d_len < $min ) { $len = $d_len; $min = $d_len; } } print $len;