my $stri="abctest"; my @one=('a','b','c','d','e','f','g'); my $part; my $lone=@one; my $first_char=substr($stri,0,1); #print "\n$first_char"; my $second_char=substr($stri,1,1); #print "\n$second_char"; my $third_char=substr($stri,2,1); #print "\n$third_char"; if ($first_char eq 'a' || $first_char eq 'b'){ for(my $ne=0;$ne<$lone;$ne++){ if ($second_char eq $one[$ne]) { if ($third_char ne 'c' || $third_char ne 'd'){ $part=substr($stri,0,2); print "\nThe string in part:"; print"\n$part"; } } } } if ($first_char eq 'a' || $first_char eq 'b'){ for(my $ne=0;$ne<$lone;$ne++){ if ($second_char eq $one[$ne]){ if ($third_char eq 'c' || $third_char eq 'd'){ $part=substr($stri,0,3); print "\nThe string in part:"; print"\n$part"; } } } }