while ($text =~ m|(.*?).*?(.*?)|sg) { print "Found job number $1 in location $2 \n"; } #### my $regexp = ''; $regexp .= "(?=.*?<$_>(.*?))" foreach qw(jobnumber location); $regexp .= '.*?'; while ($stuff =~ m|$regexp|sog) { print "Found job number $1 in location $2 \n"; }