use 5.012; use warnings; my $text = <= 0) { push @lines, substr $text, $pos, $sep - $pos; $pos = $sep + 1; } else { push @lines, substr $text, $pos; $pos = $len; } } my @sources = map { my $start = index $_, "'"; my $stop = index $_, "'", $start + 1; if (index($_, 'source') >= 0 and $start >= 0 and $stop >= 0) { (substr $_, ++$start, $stop - $start) } else { () } } @lines; say for @sources;