my @loads_of_stuff; while ( my $line = ) { chomp $line; while ( $line =~ m/#input(.+?)#end/g ) { push @loads_of_stuff, $1; } }