use CGI qw(:html4); chdir "$ENV{'DOCUMENT_ROOT'}/foo"; my @toshow = grep {-f} # filter to only regular files glob('*.{png,jpg,html}'); print map { a({ -style => q(Color: #000000; font-size: 13px;), -href => "/foo/$_" }, $_ ) } @toshow;