in reply to Print word from text file that is not an exact match

You can use proper regex syntax to "capture" what you want :
if (my ($name) = $line=~/(Servername[\.\w]*)/){ print "$name\n"; }

                Memory fault   --   brain fried

Replies are listed 'Best First'.
Re^2: Print word from text file that is not an exact match
by TonyNY (Beadle) on Jun 09, 2018 at 17:34 UTC
    Hi NetWallah, Thanks so much for your quick response and a solution that works! If you can please take a look at the following code and let me know what I am doing wrong I would greatly appreciate it. If I can get this to work then I will be able to accomplish what I need to do for my first perl script. I think I am close to getting this to worK? Thanks,
    my $file = "computers.txt"; print "-->>Paste computer name(s) here, press enter key, then ctrl-D k +eys<<--\n"; @computers = (<STDIN>); foreach (@computers) { open FILE, "$file"; while ($line=<FILE>){ if (my ($name) = $line=~/(@computers[\.\w]*)/){ print "name\n"; else print "no match found\n"; close FILE, "$file"; } } }
    Regards, Tony
      Paste computer name(s) here, press enter key,

      Where are you copying the names from, is is another text file ? If so, please show example

      poj
        Hi poj, Yes I am copying the names from another text file that looks something like this: Server1 Server2 Server3 Regards, Tony