Hi, Here is the code to accomplish your task. It involves too many substitutions but it accomplishes your task. I think there should be a simpler substitution which I am not aware:
use warnings; use strict; my $str = "tokena name: name1 tokenb tokena name: name2 tokenb tokena name: name3 tokenb"; $str=~s/tokena\n //g; $str=~s/tokenb//g; $str=~s/ //; $str=~s/(?:\n\n )//g; print "$str"; Output: name: name1 name: name2 name: name3 Hope this helps. -----Original Message----- From: Sharan Basappa [mailto:[EMAIL PROTECTED] Sent: Monday, April 14, 2008 9:06 PM To: Perl Beginners Subject: grabbing text between two tokens Hi, I am trying to capture the text between two tokens. These tokens always exist in pairs but can occur N times. I somehow dont get what I want. e.g. In the example below, I would like to capture text between tokena and tokenb. So it should capture name1 and name2. $str = "tokena name: name1 tokenb tokena name: name2 tokenb"; $str =~ m/tokena(.*)tokenb/ms; print $1; When I run this program, I get name: name1 tokenb tokena name: name2 Any suggestions? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/