例如输入全小写abc,则能够生成abc,Abc,aBc,ABc,abC,AbC,aBC,ABC:
#!/usr/bin/perl -w $abc='abc'; while($abc){ print $abc.$/; $abc = jia1($abc); } sub jia1{ my ($words) = (@_); if($words =~ /^[A-Z]+$/){return 0} my @words_array = split('',$words); my $jinwei = 1; foreach (@words_array){ if($jinwei == 1) { if($_ =~ /^[a-z]$/){ $_ = uc $_; $jinwei = 0; }elsif($_ =~ /^[A-Z]$/){ $_ = lc $_; $jinwei = 1; } } } $words = join('',@words_array); return $words; }