#! perl -l use strict; use warnings; my $s = 'uvXYZdabcXYZfg'; while ($s =~ /(\w\w\w)*?(XYZ)/g) { print 'Found match ', $1, $2, ' at pos: ', pos $s; } print '-----'; while ($s =~ /(abc)*?(XYZ)/g) { print 'Found match ', $1, $2, ' at pos: ', pos $s; } #### 22:35 >perl 1476_SoPW.pl Found match abcXYZ at pos: 12 ----- Use of uninitialized value $1 in print at 1476_SoPW.pl line 28. Found match XYZ at pos: 5 Found match abcXYZ at pos: 12 22:35 >