On 9/8/11 Thu Sep 8, 2011 9:38 AM, "Marc" <sono...@fannullone.us> scribbled:
> Jim and David, > >> m/^[aeiouy]+$/i > > I tried your suggestions but it still gives the same result: > > my $string = 'Off The Menu'; > > my @words = split(/ /, $string); > my @new_words; > foreach my $word (@words) { > if ((length $word >= 3 and length $word <= 4) and ! ($word =~ m/^[aeiouy]+$/i > or $word =~ m/^[bcdfghjklmnpqrstvwxz]+$/i)) { > $word = uc($word); > } > push @new_words, $word; > } > $string = "@new_words"; > > print $string . "\n"; > > gives me "OFF THE MENU". Then the problem probably lies with the complex logical expression, which is too complicated for me to parse easily. You can use the substitution operator s/// to match and modify strings in one step. Note also that the only number <= 3 and >= 4 at the same time is 3! So try this: use strict; my $string = 'Off The aei xxx aeiou bcdfg Menu'; my @words = split(/ /, $string); my @new_words; foreach my $word (@words) { if( length $word == 3 ) { $word =~ s/^([aeiouy]+)/uc $1/ie; $word =~ s/^([bcdfghjklmnpqrstvwxz]+)$/uc $1/ie; } push @new_words, $word; } $string = "@new_words"; print $string . "\n"; ... which gives on my system: Off The AEI XXX aeiou bcdfg Menu -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/