my $pattern = shift; #get the lines you're looking for in the file open HIST, "$HOME/.bash_history" or die "Couldn't open history file: $!\n"; my @list = grep { /$pattern/ and chomp and $_ } ; close HIST; #ask and run the commands foreach my $com (@list) { print "run [$com] (y/n)? "; my $ans = ; $ans =~ /^y/i && do { my $result = `$com`; # error checking here print "result: $result\n"; }; }