in reply to Pattern for a single word

It's difficult to understand what you're looking for. Three guesses:

#!/usr/bin/perl use strict; use warnings; my @wordlist = ( 'He_is_super_hero_Spiderman', 'He_was_a_super_actor_Tom', 'This_line_is_not_supposed_to_match', ); # Showing the original list print "Original list:\n"; foreach my $word_element (@wordlist) { print "$word_element\n"; } print "\n"; # Returning whole line of any containing matching text print "Finding whole lines containing matches:\n"; foreach my $word_element (@wordlist) { if ($word_element =~ /Spiderman|Tom/) { print "$word_element\n"; } } print "\n"; # Using $1 to extract the found text print "Finding and extracting matches:\n"; foreach my $word_element (@wordlist) { if ($word_element =~ /(Spiderman|Tom)/) { print "$1\n"; } } print "\n"; # Using split to break up the words print "Not actually looking for matches, just extracting the last word +:\n"; foreach my $word_element (@wordlist) { my @wordlettes = split /\_/, $word_element; print "$wordlettes[-1]\n"; } print "\n"; exit;

Results:

Original list: He_is_super_hero_Spiderman He_was_a_super_actor_Tom This_line_is_not_supposed_to_match Finding whole lines containing matches: He_is_super_hero_Spiderman He_was_a_super_actor_Tom Finding and extracting matches: Spiderman Tom Not actually looking for matches, just extracting the last word: Spiderman Tom match