I suggest you better put all the "keywords" in array , then use a loop to handle it...
my $hund= "hund m-a-u-s katze k.a.t.z.e. maus xyz 1234"; my @dings = ("hund", "Sudarshan", "m-a-u-s", "k.a.t.z.e.", "xyz", "Connie", "123") ; for (@dings) { if ($hund =~ /$_/) { print "'$_' found at hund\n" } else { print "'$_' not found in Hund\n" } ; } Result : 'hund' found at hund 'Sudarshan' not found in Hund 'm-a-u-s' found at hund 'k.a.t.z.e.' found at hund 'xyz' found at hund 'Connie' not found in Hund '123' found at hund Rgds, Connie ----- Original Message ----- From: "Sudarshan Raghavan" <[EMAIL PROTECTED]> To: "Perl beginners" <[EMAIL PROTECTED]> Sent: Friday, July 19, 2002 4:28 PM Subject: Re: Pattern-Matching var - interpolation. > On Fri, 19 Jul 2002, Angerstein wrote: > > > Hello, > > I have a very unfunny problem, on which i am working for hours. > > > > I need to find out if a string contains an other specified string. > > I want to use pattern-matching. > > I canīt get a match together which make this. Look at my examples, > > none of the Matchings using vars works. If I replaces the vars to normal > > strings it works like it should. > > I am using perl 5.6 on a aix 4.3.3. > > > > Thanks for help! > > ############################################ cut > > ################################################# > > #!/usr/bin/perl -w > > > > my $hund= "hund m-a-u-s katze k.a.t.z.e. maus xyz 1234"; > > my $dings1 = "hund"; > > my $dings2 = "m-a-u-s"; > > my $dings3 = "k.a.t.z.e."; > > my $dings4 = "xyz"; > > my $dings5 = "123"; > > > > if ( $dings1 =~ /\Q$hund/) { > > print "$dings1 in \$hund";} > > You are searching for $dings1 in $hund, this must be the other way around > if ($hund =~ /\Q$hund/) > > You might also want to take a look at index (perldoc -f index). > Note, if you are searching for 'orld' in 'Hello World' the regex will > succeed. If you do not want this take look at '\b' in perldoc perlre > > > > > if ( $dings1 =~ /\Q${hund}/) { > > print "$dings1 in \$hund";} > > > > if ( $dings3 =~ /${hund}/) { > > print "$dings3 in \$hund";} > > > > if ( $dings3 =~ /\Q${hund}/) { > > print "$dings3 in \$hund";} > > > > if ( $dings5 =~ /$hund/) { > > print "$dings5 in \$hund";} > > > > if ( $dings1 =~ /\Q$hund/) { > > print "$dings1 in \$hund";} > > > > if ( $dings1 =~ /.*\Q${hund}\E.*/) { > > print "$dings1 in \$hund";} > > > > if ( $dings3 =~ /\${hund}/) { > > print "$dings3 in \$hund";} > > > > if ( $dings3 =~ /.*\Q${hund}/) { > > print "$dings3 in \$hund";} > > > > if ( $dings5 =~ /.*$hund.*/) { > > print "$dings5 in \$hund";} > > > > if ( $dings4 =~ /.*$hund.*/) { > > print "$dings5 in \$hund";} > > ###################################### EOF > > ############################################# > > > > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]