use strict; my $email = "myself\@domain.of-my.own"; my $string = "root: myself\@domain.of-my.own"; my $re = inv_str_seq($email); $string =~ /^root: $re/ and print 1; sub inv_str_seq { my($string) = @_; my @c = map { quotemeta($_) } split '', $string; my $re = "\n [^$c[0]] \n"; $re .= " | " . join('',@c[0..$_-1]) . " [^$c[$_]]\n" for (1 .. $#c); $re = qr/$re/x; return qr/$re+ (?:[^$c[0]]|$)/x; }