in reply to Unable to replace targeted newlines in a string
#!/usr/bin/perl -w use strict; my $string = "P5§2\nAAA\nBBB\nCCC\nP6§21\blah\nmore\n"; my ($first,@tokens) = (split(/\n/,$string))[0..3]; print "$first\n"; print @tokens,"\n"; __END__ Prints: P5§2 AAABBBCCC #Update: if you want the tokens in one $var, say $stuff, then #my $stuff = join("",@tokens); #print "$stuff\n"; # also prints: AAABBBCCC
|
|---|