$def =~ s/ (^\.\w+\s) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := some whitespace (.+) ## $4 := Some anything ( ## $5 ^ ## The start of string/line select ## The word 'select' \. ## A literal '.' . ## Any single character $ ## The end of the line/string ) /$2$5/x; ## put back just first word and the 'select' etc #### #! perl use warnings; use strict; my $def = <<'EOD'; .define get_user_info select user_location,user_name, user_company, &fax_header || ';style=' || letterhead, fax_printer, nvl(fax_yn,'N') into user_location, user_name, user_company, fax_header, fax_printer, fax_yn from security_header where user_id = lower(substr(user,5,10)) .. EOD $def =~ s/ ( \A \. \w+ \s ) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := Some whitespace (.+?) ## $4 := Some anything ( ## $5 \s+ ## Some whitespace select ## The word 'select' [^.]+ ## Lots of anything except a '.' \. \. \Z ## Two '.'s and the end of line ) /$2$5/smx ## . matches \n; ^ & $ match lines with the string or die 'Failed to match'; print $def;