Hanson wrote: > > Hi! > > I need to remove the first n underscores from various > strings if there are more than two currently present in the > string. The total number of underscores will vary. For > example, if I have the following strings: > > $a = "Now_is_the_time_for_all" > $b = "The_quick_brown_fox_jumped" > $c = "foo_bar_baz" > > I need to change them to: > > $a = "Nowisthetime_for_all" > $b = "Thequickbrown_fox_jumped" > $c = "foo_bar_baz" # No change required.
#!/usr/bin/perl -w use strict; while ( <DATA> ) { my $count = tr/_//; my $num_to_remove = $count - 2; if ( $count > 2 ) { s/_// while $num_to_remove--; } print; } __DATA__ Now_is_the_time_for_all The_quick_brown_fox_jumped foo_bar_baz John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]