#!/usr/bin/perl -w use strict; my $pattern = "JEJE"; my $string = "EJKJUJHJDJEJEJEDEJOJOJJJAHJHJSHJEFEJUJEJUJKIJS"; # from the $pattern, generate a $regex like this: my $regex = "JEJE|.EJE|J.JE|JE.E|JEJ."; # and use it like this: my (@matches) = $string =~ m/$regex/g; print join ("\n", @matches), "\n"; __END__ prints: JDJE JEJE JEFE JUJE