local $SIG{__DIE__} = sub { my ($d) = ( $_[0] =~ /line (\d+)\.$/ ); unless ($d) { print STDERR $_[0]; return; } my $context = 3; #number of context lines seek DATA,0,0; while() { next if $. < ($d-$context); #cycle until context starts warn ($. == $d ? '>' : ' ') #mark line if it contains the error .sprintf('%4d ',$.) #use 4-place line numbers (alignment) .$_; #show code on line last if $. > ($d+$context); #move on once we've finished context } };