Owen wrote: > > I would like to replace all instances of > > @non_space_characters[non_space_characters] with > $non_space_characters[non_space_characters] > > The program below gets the first one only. How do I get the others? > > --------------------------------------------------- > #!/usr/bin/perl -w > use strict; > > my $line; > while (<DATA>){ > $line=$_;
Why not just: while ( my $line = <DATA> ) { > #$line=~s/(@)(\S+)(\[\S+\])/\$$2$3/g; > $line=~s/(@)(\S+\[\S+\])/\$$2/g; +, * and ? are greedy so they will match the longest string that they can. Your complete line up to the newline will be matched by \S+ so you want to be more selective in what you will match. Since user defined variables must consist alpha-numeric and the _ characters you can use \w+ instead. Also, why are you capturing the @ into $1? $line =~ s/@(\w+\[[^]]+])/\$$1/g; > print "$line\n"; > > } > __DATA__ > @[EMAIL PROTECTED]@banana[4]; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>