use strict; use warnings; use Test::More tests => 2; use Test::Warn; # Your code which gives an expected warning sub foo { warn "Stripe Webhook Error: Invalid Stripe Signature\n"; } sub bar { STDERR->print ("Stripe Webhook Error: Invalid Stripe Signature\n"); } # Test your code warning_is { foo (); } "Stripe Webhook Error: Invalid Stripe Signature\n", 'Invalid sig warning issued'; warning_is { bar (); } "Stripe Webhook Error: Invalid Stripe Signature\n", 'Invalid sig STDERR print issued';