Opening file and executing an action

I want the script to read the directory I am running the script from and print the contents of any file that has GX in it's title. This is the code needed[I think]. But how do I combine it?

#!/usr/bin/perl

opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);

foreach $item (@list){
  if($item =~ /GX/){
    print "$item\n";
  }
}

if(-e $filename){
 open(FILE,"$filename");
 while(<FILE>){ print };
 close(FILE);

you can use the globbing with perl!
Search on google perl globbing tutorial

Ok not sure how to use 'glob', never heard of it^^

#!/usr/bin/perl -w

@files = <*>;
foreach $file (@files) {
  print $file . "\n";
} 

I did this:

#!/usr/bin/perl
while($x = <*>) {
    open(FILE,"$x") || die "Couldn't open $x for reading.\n";
    while(<FILE>){
        if(/GX/) {
            print "$x: $_";
        }
    }
}

But that only prints out lines and not the content of the files with GX. How can I make it print out the content in the files with GX in their name?

---------- Post updated at 08:23 AM ---------- Previous update was at 08:10 AM ----------

I want it to check the home directory for each file that has GX in the file-name and print out the contents within. Not a list of the files or only lines within a file.

I don't know about perl, in the awk you can do something like this :

ls -l | grep "^-" | awk '$0 ~/GX/ {print "cat "$NF }' | sh 

Thxz panyam, but I prefer it in perl script. Been trying many ways already with scripting, I am not backing out now^.^

---------- Post updated at 09:29 AM ---------- Previous update was at 08:37 AM ----------

Got it working!

#!/usr/bin/perl 
 
opendir(CURRENT,"."); 
@list = readdir(CURRENT); 
closedir(CURRENT); 
 
foreach $item (@list){ 
  if($item =~ /GX/){ 
    print "$item\n"; 
    system("cat $item");
  } 
}

My first code was alright just needed some polishing!