#!/usr/bin/perl -w use strict; #case A my @matches = "hello awesome home" =~ /(el).*(om)/; foreach (@matches) { print $_,"\n"; } ## el ## om #case B @matches = "hello awesome home" =~ /(el)(.*)(om)/; foreach (@matches) { print $_,"\n"; } ## el this is the (el) ## lo awesome h now there is another "om" before last om ## om this is last (om) #Case C #lets say that we only wanted this stuff between the first (el) #and the last (om)? And we just want a scalar. #this is done with an array slice. my $stuff = ("hello awesome home" =~ /(el)(.*)(om)/)[1]; print "$stuff\n"; #prints "lo awesome h" #Case D my @stuff = "hello awesome home" =~ /(el)(.*)(om)/; print pop (@stuff)."\n"; #prints: om print pop (@stuff)."\n"; #prints: lo awesome h print pop (@stuff)."\n"; #prints: el #Case E @stuff = "hello awesome home" =~ /(el)(.*)(om)/; print shift (@stuff)."\n"; #prints: el print shift (@stuff)."\n"; #prints: lo awesome h print shift( @stuff)."\n"; #prints: om