http://qs321.pair.com?node_id=525215


in reply to Removing chars from a word from an array

Let's try this again!

my $word = 'abracadabra'; my @list = qw( a b c d e ); my %list = map { $_ => 1 } @list; foreach (@list) { delete $list{$_} if $word =~ s/\Q$_//; } @list = keys %list; print("remaining word: ", $word, "\n"); # raaabra print("remaining list: ", @list, "\n"); # e
outputs
remaining word: raaabra remaining list: e

If you wish to replace all intances of the characters in @list, replace s/\Q$_// with s/\Q$_//g. The output would then be the following for the above snippet:

remaining word: rr remaining list: e