#!/usr/bin/perl -w use strict; my $string='ABCD'; my $string1='DCBA'; my $test='.*?AB'; print "Matched in $string" if $string =~ $test; # Prints Match. print "Matched in $string1" if $string1 =~ $test; # Does not print Match.