I'm assuming that by "biggest name", you mean longest name. In that case, your problem is with
$file gt $greatest. This does a string comparison of those two scalars, which is not what you want. Instead, you want to compare the
length of the scalars. Do that with
length($file) > length($greatest).
More generally, I'd go with something like this:
#!perl -w
use strict;
use CGI ":standard";
my $longest = "";
my $dir = '/data';
opendir DIR, $dir or die "Couldn't readdir $dir";
while(my $file = readdir DIR) {
print "'$longest'\n";
$longest = $file if length($file) > length($longest);
}
closedir DIR;
print header,
start_html("Longest filename"),
"Longest filename in '$dir' is '$longest', which has ",
length($longest),
' characters.',
end_html;