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
In reply to Re: Search and Extract from String
by poj
in thread Search and Extract from String
by madbee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |