#!/usr/bin/perl -w use strict; my $text ="some text START text I don't want START only text I want END"; my $wanted = ($text =~ /.*START (.*) END$/)[0]; my $wanted2 = ($text =~ /.*(START .* END)$/)[0]; print "wanted=\"$wanted\"\n"; print "wanted2=\"$wanted2\"\n"; __END__ prints: wanted="only text I want" wanted2="START only text I want END" #### my ($x,$y) = ($text =~ /.*(START (.*) END)$/)[0,1]; print "x=$x y=$y\n"; #prints: x=START only text I want END y=only text I want