#!/usr/bin/perl -w use strict; my @strings = ("CATINTHEHATWITHABAT", "WERWERWAT134wAt"); my $regex = '\wAT'; foreach my $string (@strings) { while ( $string =~ m/($regex)/gi) { printf "%s found at pos %2d in %s\n", $1, pos($string)-length($1)+1, $string; } } __END__ Prints: CAT found at pos 1 in CATINTHEHATWITHABAT HAT found at pos 9 in CATINTHEHATWITHABAT BAT found at pos 17 in CATINTHEHATWITHABAT WAT found at pos 7 in WERWERWAT134wAt wAt found at pos 13 in WERWERWAT134wAt