my $report = do { opendir my $dh, $path or die "open '$path' $!"; my ( $name, $mtime ) = ( '', ~0 ); while ( my $file = readdir $dh ) { stat "$path/$file"; ( $name, $mtime ) = ( $file, -M _ ) if $file =~ /B1006/ and $mtime > -M _; } $name; };