#!/usr/bin/perl -w use strict; my $string = 'anotherwordhere foobar wordhere baz qux wordhere'; $string =~ /anotherwordhere\s+(.*?) wordhere/; print "Non-greedy match: '$1'\n"; $string =~ /anotherwordhere\s+(.*) wordhere/; print "Greedy match : '$1'\n"; #### Non-greedy match: 'foobar' Greedy match : 'foobar wordhere baz qux'