my $to_match = 'xyz123abc'; $to_match = join '\.*', map {quotemeta} split //, $to_match; # $to_match is now 'x\.*y\.*z\.*1\.*2\.*3\.*a\.*b\.*c'. $to_match = qr/$to_match/; /$to_match/ && print for <>;