#!/usr/bin/perl -w use strict; my %cams; while(){ chomp; my $lm = -M $_; $cams{$lm} = $_; } my $recent = (sort keys %cams)[0]; open(my $fh, "<", $cams{$recent}) or die("Cannot open file! $!"); flock($fh, 4); print "Content-type: image/jpeg\n\n"; binmode STDOUT; $/ = \8192; # read data in 8kbyte chunks rather than from LF to LF # see perldoc perlvar (thanks Aristotle id://189265) print while <$fh>; close($fh); __DATA__ ../httpdocs/cam/cam.jpg ../web_users/someone_else/cam.jpg