in reply to Search and Extract from String
You can a match and capture part of the string with brackets(). The captured part is stored in the variable $1. For example ;
poj#!perl use strict; while (<DATA>){ # capture word with () # [- ] character is space or dash if (m/(design|otherword)[- ]controlled/i){ # captured word is in $1 print "Word < $1 >found in $_"; } else { print "No word found in $_"; } } __DATA__ This is a design controlled string This is a design-controlled string This is a controlled design string This is an otherword-controlled string
|
|---|