Else try This.. #!/usr/local/bin/perl use strict;
my $string = "Theres more than 1 way to do it"; if ($string =~ /\w+$/){ print "Hooray! pattern found\n"; print $&; } Use the inbuilt perl variables.. $` prints the pre matching part, $& gives the matched variale and $' gives the post matching part Sijo On Monday October 2 2006 1:16 pm, Michael Alipio wrote: > Hi, > > Suppose I have this: > > #!/usr/local/bin/perl > use strict; > > my $string = "Theres more than 1 way to do it"; > if ($string =~ /\w+$/){ > print "Hooray! pattern found"; > print $1; > } > > My goal is to print the last word. > However, it only prints "Hooray! pattern found"; > > Any idea what's wrong with $1?? > > Thanks > > > > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>