#! usr/bin/perl use strict; use warnings; $_=' A a A '; while (/(\s)(a)(\s)/ig) { print "The text matches the pattern '$&' at position " . pos() . ".\n"; # uncomment this to rewind #pos() = pos() - 1; }