my $superstring = "123abc.def.ghi"; my $substring = "abc.def.ghi"; my $prefix = "123"; #### #### (pfff where is my head at. This won't work of course) $superstring =~ m/$B$A/ $superstring =~ m/$prefix$superstring/;