use strict; use warnings; use utf8; use Encode qw/encode decode decode_utf8 encode_utf8 from_to/; my $instr = decode('utf8', ); my $len = -1; while($instr =~ /([Cc].*?[wW].*?[Ww])(.*)/ ) { $len = length("$1"); $instr = "$2"; } print $len;