Sunday, June 24, 2012

Write function to get string between two specified words.

#!C:/Perl/bin/perl -w

my $string = "Hi, this is Rabindra Nayak! I work on Perl Scripting on UNIX platform.";

my $searchText = getText( $string, 'on', 'on' );

print $searchText;

sub getText
{
        return $1 if ( $_[0] =~ /$_[1] (.*?) $_[2]/ );
}

Output : Perl Scripting

No comments :