use Devel::Peek; open my $fh, '>', \my $memory_file; for (qw(abc def ghi jkl mno)) { print $fh $_; Dump $memory_file; if ( $memory_file =~ m/^(.*)$/ ) { print "==> matched: $1\n" } } __END__ SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abc"\0 CUR = 3 LEN = 8 ==> matched: abc SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdef"\0 CUR = 6 LEN = 8 ==> matched: abcdef SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghi" <--- !! CUR = 9 LEN = 16 SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghijkl"\0 CUR = 12 LEN = 16 ==> matched: abcdefghijkl SV = PV(0x75cce8) at 0x783f70 REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0x7b2e10 "abcdefghijklmno"\0 CUR = 15 LEN = 16 ==> matched: abcdefghijklmno