#!/usr/bin/perl -w use strict; my %seen; while (<>) { s![\$\%\@]([a-zA-Z]\w*)!$seen{$1}++!eg } my @once = sort grep { $seen{$_} == 1 } keys %seen; if (@once) { print "Possible unused variables found: \n\n", join("\n", @once), "\n"; } #### $ perl use.pl foo.pl Possible unused variables found: var_a