#so you get something like this: my $index = 0; if ( lenght $str1 < length $str2 ) { $index= index $str2,str1; } else { $index= index $str1,str2; }