$string = '\bjust\b'; $/ = ""; while(<>){ s/ *\n */ /g; while(/\b$string\b/ig){ $count++; $key = $&; $pre = substr ($`, -25); $post = substr ($', 0, 25); $file = $ARGV; $file =~ s#.*/([^/]+)$#$1#; printf "%5d | %s | %25s|%s|%-25.25s\n", $count, $file, $pre, $key, $post; } } exit;