directory structure prj45 |-- blk1 | |-- block.config | |-- checklist1 | | |-- rev1 | | | |-- rev.config | | | `-- rev_info.txt | | |-- rev2 | | |-- task.config | | |-- temp_kjani_rev2 | | | |-- rev.config | | | `-- rev_info.txt | | |-- temp_kmandal_rev1 | | `-- temp_sthykkoo_rev1 | `-- checklist3 | |-- rev1 | `-- temp_apangark_rev1 #### code which i have tried using sub routine: sub get_html_link_info { my ( $dir, $word ) = @_; $word=~s/(\S+)\s*/$1/g; my @dirs = <$dir/rev*>; my $num_dirs = scalar @dirs; if ( $num_dirs != 1) { die "Unexpected directory configuration. Expected single '$dir' rev* folder, " . "found $num_dirs folder(s)"; } $dir = shift @dirs; my @files = <$dir/*.html>; my $num_files = scalar @files; if ( $num_files != 1) { die "Unexpected directory configuration. Expected single .html file, " . "found $num_files .html files(s)"; } my $link = shift @files; return ($word, $link ); }