[Solved] how to do match a word in a line in perl and remove it and using them separately? [closed]


#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

my $count = 0;

while (<DATA>) {
  chomp;
  for (split / abc /) {
    $count++;
    say "value $count=", ($count == 1 ? '' : ' '), $_;
  }
}

__DATA__
123 abc xyz
456 abc sdf
789 abc ghj

Or, perhaps a more data-driven approach to determining which rows omit the space after the =:

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

my %nospace = (
  1 => 1,
);

my $count = 0;

while (<DATA>) {
  chomp;
  for (split / abc /) {
    $count++;
    say "value $count=", ($nospace{$count} ? '' : ' '), $_;
  }
}

__DATA__
123 abc xyz
456 abc sdf
789 abc ghj

solved how to do match a word in a line in perl and remove it and using them separately? [closed]