If I read this text ile from open (FILE,"mytextfile.txt"); print FILE;

The information in the file is fully displayed. I just need to partially i,e only menu one option should be displayed. Now I am creating two text files, one for firts menu option and other for second menu option and pulling them seperately. Is it possible to have bothe menus in singe file and called menus separately.

Of course you can. You would need to read each line individually and figure out whether you want to print it or not, depending on some conditions.

For example, something like this:

Code

my $select = $something; # something could be "#Menu1" or #Menu2 ENDFILE: while (my $line = <FILE>) { next while $line !~ /$select/; # discard lines until we arrive at the right menu option print $line; # print the menu option line while ($line = <FILE>) { # get tge following lines last ENDFILE if $line =~ /^#/; # end the loop if we get to a new menu option print $line; } }

But this does not look too good and depends too much on assumptions made about the file format. A better option would be to define your menu file differently, for example something like this:

Code

1:#Menu1 1:--------- 1:1. Option 1 1:2. Option 2

2:#Menu 2 2:---------- 2:1. option 1 2:2. Option 2

It is then cleaner, easier and far more robust to print only the relevant lines, depending on the menu number chosen, with something like this: