use Algorithm::Loops qw( Filter ); my $string = Filter { s/^\s+|\s$//g } EXPR;