in reply to matching lines in a long string

Athanasius and AnomalousMonk already explained the issue. I just wanted to add: The most performant way is the following; it avoids splitting the lines into a list first.

use warnings; use strict; my $s = <<'EOF'; int t; //variable t t->a=0; //t->a does;; something printf("\nEnter the Employee ID : "); scanf("%d", ptrx->eid); //employee id ptrx->eid printf("\nEnter the Employee Name : "); scanf("%s", ptr->name); return 0; EOF open my $fh, '<', \$s or die $!; while ( my $line = <$fh> ) { chomp($line); print "<$line>\n"; } close $fh;