#!/usr/bin/perl use strict; use warnings; my $book= "^\\s\*book ref \#"; my $book_res = $book =~ "/^\\s\*owner \#/"; my $title = "^\\s\*title "; my $title_res = $title =~ "/^\\s\*title /"; foreach () { next unless /$book|$title/ip; print ; } # here i would like to access the regex matches as scalers __DATA__ Book ref #4346 Lent: Sun Jul 12 03:26:43 BST 2015 status Lent Description: classic title blah blah blah last used: 2 color red Pages 238 Publisher Bca Type Hardback Location: N/a Author R jones #### resulted matches Book ref #4346 title blah blah blah