Here I am trying to filter only the elements that do not have a substring world and store the results back to the same array. What is the correct way to do this
world
That would be grep():
grep()
#!/usr/bin/perl use strict; use warnings; my @arr = ('hello 1', 'hello 2', 'hello 3', 'world1', 'hello 4', 'world2'); my @narr = ( ); print "@arr\n"; @narr = grep(!/world/, @arr); print "@narr\n";