fork download
  1. #!/usr/bin/perl
  2. use feature 'say';
  3. use strict;
  4. use warnings;
  5.  
  6. my $str = " a \n \n b\n";
  7. say $str =~ s/^\s*|\s*$//mgr;
  8.  
  9. $_ = " a \n\n b\n";
  10. s/^\s*|\s*$//gm;
  11. print "$_\n";
  12.  
Success #stdin #stdout 0.01s 5656KB
stdin
Standard input is empty
stdout
a
b
ab