fork download
  1. #!/usr/bin/perl
  2.  
  3. my @my_arr = ("test1", "test2", "test3", "test2", "test5", "test2", "test6");
  4. my $what = 'test2';
  5. my $then = 'best2';
  6.  
  7. foreach ( @my_arr ) {
  8. s/^$what$/$then/ and last;
  9. }
  10.  
  11. print $_, "\n" for @my_arr;
  12.  
Success #stdin #stdout 0s 6044KB
stdin
Standard input is empty
stdout
test1
best2
test3
test2
test5
test2
test6