#!/usr/local/bin/perl $dir = $ARGV[0]; open(HANDLE,$dir) || die "ERROR in opening file"; @allfiles = readdir HANDLE; close(HANDLE); foreach $files (@allfiles) { open(FH,"<",$files)|| die "ERROR in opening file"; foreach $line () { $line =~ m/ \^module\ /g ; @next = split(/\s+/,$line); } close(FH); } print "$next[0]\n"