my $x; @out_list = map { ($x = $_) =~ s/foo(.*?)bar/$1 baz/; $x } @in_list; #### my @subst = map { s/\s+/_/g } @list;