in reply to regex needed

I forgot to mention that I need to exclude the ">" sign if it exists so in this case I would have two matches:
>Sensor30 Sensor30

Replies are listed 'Best First'.
Re^2: regex needed
by Crian (Curate) on Nov 18, 2008 at 13:58 UTC

    Perhaps this one is, what you are looking for?

    C:\Daten\perl>cat match.pl #!/usr/bin/perl use strict; use warnings; my $var = 'Sensor30'; while (<DATA>) { print if /^>?\Q$var\E$/; } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3 C:\Daten\perl>perl match.pl >Sensor30 Sensor30

    Without a regular expression:

    C:\Daten\perl>cat match.pl #!/usr/bin/perl use strict; use warnings; my $var = 'Sensor30'; while (<DATA>) { chomp; print "$_\n" if $_ eq $var or $_ eq '>' . $var; } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3 C:\Daten\perl>perl match.pl >Sensor30 Sensor30
      Thats what I was missing...Thank you!

      I modified it a bit to include the space if it exists:

      my $var = 'Sensor30'; while (<DATA>) { chomp; if (/^(>\s*)?\Q$var\E$/) { print "MATCH => $_\n"; } } __DATA__ >Sensor30 >FooSensor30 > Sensor30 Sensor300 Sensor30 >Sensor3